[Android]requestFeature() must be called before adding content

 public void onCreate(Bundle savedInstanceState){

        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        view = new MainView(getBaseContext());

        SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
        view.hasSaveState =settings.getBoolean("save_state",false);
        if (savedInstanceState != null) {
            if (savedInstanceState.getBoolean("hasState")) {
                //load();
            }
        }
        setContentView(view);
    }

这样的代码会报错, requestFeature() must be called before adding content

requestWindowFeature(Window.FEATURE_NO_TITLE);

放到super.onCreae()前面就行了。



郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。