Window属性列举如下:FEATURE_OPTIONS_PANEL = 0; 功能不明,参见后面的说明(默认使能)FEATURE_NO_TITLE = 1; 无标题栏FEATURE_PROGRESS = 2; 在标题栏上显示加载进度,例如webview加载网页时(条状进度条)FEATURE_LEFT_ICON = 3; 在标题栏左侧显示一个图标FEATURE_RIGHT_ICON = 4; 在标题栏右侧显示一个图标FEATURE_INDETERMINATE_PROGRESS = 5; 不确定的进度(圆圈状等待图标)FEATURE_CONTEXT_MENU = 6; 上下文菜单,相当于PC上的右键菜单(默认使能)
FEATURE_OPENGL = 8; 如果开启OpenGL,那么2D将由OpenGL处理(OpenGL中2D是3D的子集)PROGRESS_VISIBILITY_ON = -1; 进度条可见PROGRESS_VISIBILITY_OFF = -2; 进度条不可见PROGRESS_INDETERMINATE_ON = -3; 开启不确定模式PROGRESS_INDETERMINATE_OFF = -4; 关闭不确定模式PROGRESS_START = 0; 第一进度条的最小值PROGRESS_END = 10000; 第一进度条的最大值PROGRESS_SECONDARY_START = 20000; 第二进度条的最小值PROGRESS_SECONDARY_END = 30000; 第二进度条的最大值
应用示例: 1、隐藏标题栏
requestWindowFeature(Window.FEATURE_NO_TITLE);2、在标题栏显示进度条
requestWindowFeature(Window.FEATURE_PROGRESS); setContentView(R.layout.progressbar_1); setProgressBarVisibility(true); final ProgressBar progressHorizontal = (ProgressBar)findViewById(R.id.progress_horizontal); setProgress(progressHorizontal.getProgress() * 100); setSecondaryProgress(progressHorizontal.getSecondaryProgress()* 100);3、使用自定义标题栏
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.xxx); getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.my_title_bar);4、清除标题栏内容,而区域保留
((ViewGroup)getWindow().findViewById(com.android.internal.R.id.title_container)).removeAllViews();5、隐藏标题栏
((ViewGroup)getWindow(). findViewById(com.android.internal.R.id.title_container)).setVisibility(View.GONE);6、显示标题栏
setVisibility(View.VISIBLE);其他注意事项
(1) requestWindowFeature()要在setContentView()之前调用; (2) 设置各种Feature,是具有排它性的,一旦设置,后续不可更改为别的类型; (3)当使用TabHost(由ActivityGroup派生)时,各个Tab里的Activity,要么都是NO_TITLE,要么都是CUSTOM_TITLE,无法分别进行设置。FEATURE_CUSTOM_TITLE = 7; 自定义标题栏,该属性不能与其他标题栏属性合用
自定义标题栏背景没有填充满解决方法 使用Theme 和Style:
AndroidManifest.xml 使用自定义标题的那个Activity添加属性 android:theme="@style/XTheme"
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="B.P1" android:versionCode="1" android:versionName="1.0"><uses-sdk android:minSdkVersion="7" /><application android:icon="@drawable/icon" android:label="@string/app_name"><activity android:name=".MainActivity" android:label="@string/app_name" android:theme="@style/XTheme"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity></application></manifest>在values添加:style.xml和theme.xml
<?xml version="1.0" encoding="utf-8"?><resources><style name="XTheme" parent="android:Theme"><item name="android:windowTitleStyle">@null</item><item name="android:windowTitleBackgroundStyle">@style/StatusBarBackground</item><item name="android:windowContentOverlay">@null</item></style></resources> <?xml version="1.0" encoding="utf-8"?><resources><style name="StatusBarBackground" ><item name="android:background">#000</item> </style></resources>体更多请参考:http://www.cnblogs.com/GnagWang/archive/2011/03/31/2001067.html
转载于:https://www.cnblogs.com/xiaobuild/archive/2011/08/19/2145851.html
相关资源:JAVA上百实例源码以及开源项目