您的位置:首页 > 移动开发 > Android开发

Android程序窗体显示:requestWindowFeature()

2015-09-13 14:44 573 查看
[size=large]本文围绕以下五个部分展开: [/size]

[size=large]一、requestWindowFeature()[/size]
[size=large]二、FEATURE_CUSTOM_TITLE:自定义标题[/size]
[size=large]三、FEATURE_INDETERMINATE_PROGRESS[/size]
[size=large]四、FEATURE_LEFT_ICON[/size]
[size=large]五、FEATURE_NO_TITLE[/size]


[size=large]一、requestWindowFeature()[/size]

[size=medium]我们在开发Android应用程序时经常会需要软件全屏显示、自定义标题(使用按钮等控件)或其他的需求,因此需要掌握Android应用程序窗体显示的方法。[/size]

[size=medium]一个重要方法就是:requestWindowFeature(featrueId)。它的功能是启用窗体的扩展特性,参数是Window类中定义的常量。[/size]

[align=center][/align]


[size=large]二、FEATURE_CUSTOM_TITLE:自定义标题[/size]

// 自定义标题。当需要自定义标题时必须指定。如:标题是一个按钮时
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.customtitle);


[size=medium]customtitle.xml。[/size]

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"/>
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="文本" />

</LinearLayout>


[align=center][/align]


[size=large]三、FEATURE_INDETERMINATE_PROGRESS[/size]

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.activity_main);
getWindow().setFeatureInt(Window.FEATURE_INDETERMINATE_PROGRESS, R.layout.progress);
// 必须得加上否则显示不出效果 可以通过这个在以后设置显示或隐藏
setProgressBarIndeterminateVisibility(true);


[size=medium]progress.xml。[/size]

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">

<ProgressBar android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
style="?android:attr/progressBarStyleSmallTitle">

</ProgressBar>

</LinearLayout>


[align=center][/align]


[size=large]四、FEATURE_LEFT_ICON[/size]

requestWindowFeature(Window.FEATURE_LEFT_ICON);
setContentView(R.layout.activity_main);
getWindow().setFeatureInt(Window.FEATURE_LEFT_ICON, R.mipmap.ic_launcher);


[align=center][/align]


[size=large]五、FEATURE_NO_TITLE[/size]

requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
// 加上这句设置为全屏 不加则只隐藏title
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);


[align=center][/align]


[size=medium]整理时参考:[/size]
[size=medium][color=red]http://www.cnblogs.com/salam/archive/2010/11/30/1892143.html[/color][/size]
[size=medium][color=red]http://zhanhao.iteye.com/blog/1174914[/color][/size]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐