requestWindowFeature(Window.FEATURE_NO_TITLE);(隐藏title导航栏)
看一下我们实际使用this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
隐藏信息状态栏
运行以上程序会产生如下错误:public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);//全屏
setContentView(new DrawBitmapTest(this));this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
}
我们查看源码提示java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dream.sur/com.dream.sur.draw.SurfaceViewTestActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:189)
at android.app.Activity.requestWindowFeature(Activity.java:2735)
意思是说 requestWindowFeature 必须在 setContentView() 这个方法之前调用,后面使之 setFlags 的设置需要在 setContentView();Enable extended screen features. This must be called before setContentView().
Note that some flags must be set before the window decoration is created (by the first call to {@link #setContentView(View, android.view.ViewGroup.LayoutParams)
将title栏和时间电池信息状态栏给隐藏掉public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(new DrawBitmapTest(this));
}
如果想要仅去除title栏留下时间和电池信息状态栏可以将以上xml theme换成:<activity
android:name=".draw.SurfaceViewTestActivity"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
至此android全屏的设置已经okandroid:theme="@android:style/Theme.NoTitleBar"
public final boolean requestWindowFeature(int featureId) {
return getWindow().requestFeature(featureId);
}
转自:http://dreamthinking.blog.163.com/blog/static/205181171201251973349985/