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);
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM