引起:android.util.AndroidRuntimeException:在添加内容android异常之前必须调用requestFeature()

时间:2013-12-21 10:59:30

标签: android android-titlebar

我知道这个问题已经在堆栈上被问到但是我尝试了所有的解决方案但没有用。还有以下错误

引起:android.util.AndroidRuntimeException:在添加内容之前必须调用requestFeature()

下面是代码 -

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        **requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);**  
        setContentView(R.layout.info);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
     }

我尝试了很多链接,如下所示 - https://stackoverflow.com/search?q=requestFeature%28%29+must+be+called+before+adding+content

有没有解决方案?

2 个答案:

答案 0 :(得分:3)

试试这个

@Override
    protected void onCreate(Bundle savedInstanceState) {

        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.info);

     }

答案 1 :(得分:1)

你试过这个吗..

@Override
protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);  
    super.onCreate(savedInstanceState);   
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);     
    setContentView(R.layout.info);        
 }