cannot combine custom titles with other title features

后端 未结 6 683
孤街浪徒
孤街浪徒 2020-12-03 14:40

I am getting this error when calling the setContentView() after

    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    getWindow().setFeatureInt(Window.F         


        
6条回答
  •  [愿得一人]
    2020-12-03 15:31

    I have the same problem and here is what it worked for me:

    AndroidManifest.xml

    < application
       ...
       ...
       android:theme="@style/CustomTheme" >
    

    Styles.xml

    < style name="CustomTheme" parent="android:Theme">
    < /style>
    

    MainActivity.java

    1) super.onCreate(savedInstanceState);

    2) requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

    3) setContentView(R.layout.activity_main);

    4) getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title1);

    The order of the codes is important as shown above.

    If you have:

    1) requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

    2) setContentView(R.layout.activity_main);

    3) super.onCreate(savedInstanceState);

    4) getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title1);

    You will get this exception:

    android.view.InflateException: Binary XML file line #37: Error inflating class fragment

提交回复
热议问题