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

时间:2022-04-27 06:57:37
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);
}