android.util.AndroidRuntimeException: requestFeature() must be called before adding content 错误解决方法

Activity全屏,网上的代码如下:
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//去掉信息栏
    setContentView(R.layout.activity_main);
}

但在AS中,会提示错误:
android.util.AndroidRuntimeException: requestFeature() must be called before adding content
解决如下:
protected void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//去掉信息栏
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
posted @ 2016-01-20 16:06  Daniel-Zhang  阅读(5871)  评论(0编辑  收藏  举报