cannot combine custom titles with other title features

后端 未结 6 681
孤街浪徒
孤街浪徒 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:20

    You should use <item name="android:windowNoTitle">false</item> in your custom theme

    0 讨论(0)
  • 2020-12-03 15:23

    Maybe this question up to this time is already solved, but i post this answer for those who are having this error...i had a very similar problem, and changing the manifest file didn't work at all, but what it worked for me was go to the gradle Scripts and go to the build.gradle(Module:app) in this file, i changed the minSdkVersion and the targetSdkVersion with the same in both of them in this case for example 7, and the app runs correctly!

    0 讨论(0)
  • 2020-12-03 15:24

    I had a similar problem that drove me insane: I have 2 versions of the same app using a shared library project as their common code (over 95% of each app is made of that shared library project): One runs fine, without any problem whatsoever. The other crashes upon start with the same error message & symptoms you describe:

    You cannot combine custom titles with other title features

    The layout XML files are common as well! So, I couldn't find any explanation for this weird problem.

    After much brainstorming between me, myself and I, I discovered that the only difference between the two apps is that the one that runs fine has this in its AndroidManifest.xml:

    <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="7" />
    

    And the one that crashes has this in its AndroidManifest.xml:

    <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="13" />
    

    So, you see, the Android UI is touted as being a 4th-generation UI framework, in which the UI is declarative and independently themed, but at the end of the day it's all the same st: Developing in C (for example) for Microsoft Windows is no more time consuming than developing in Java for the Android because the Android development framework is full of landmines like this in which the compiler won't tell you anything at compile time, and the thrown exception won't tell you either. Instead, you have to rely on **luck finding that little snippet of documentation (that may or may not exist), providing you with a hint as to where to look for the root cause of the problem.

    I hope that this information will be helpful to many who experience the same problem.

    0 讨论(0)
  • 2020-12-03 15:25

    It matters which parent theme you are using:

    If I use parent="android:Theme", then android:windowNoTitle="false" works (as per @Vladimir's answer).

    However, if I use parent="android:Theme.Holo.Light", then I need to use android:windowActionBar="false" (as per @Jasper's comment). Here's my working xml using the Holo Light theme:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <style name="Theme.ScheduleTimes" parent="android:Theme.Holo.Light">
            <item name="android:windowActionBar">false</item>
        </style>
    </resources>
    
    0 讨论(0)
  • 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

    0 讨论(0)
  • 2020-12-03 15:31

    I had the same problem. I downloaded an app named BlueToothChat. So, I add the following code to the string.mxl file within the value folder:

    <resources>
        <style name="CustomTheme" parent="@android:Theme">
        <item name="android:windowNoTitle">false</item>
    </style>
    
    <string name="app_name">Bluetooth Chat</string>
    ...
    

    and then add: {Theme = "@style/CustomTheme"} to the home page of the activity page (BluetoothChat.cs):

    namespace BluetoothChat
    {
        /// <summary>
        /// This is the main Activity that displays the current chat session.
        /// </summary>
    [Activity (Label = "@string/app_name", MainLauncher = true,
           Theme = "@style/CustomTheme", ConfigurationChanges
           Android.Content.PM.ConfigChanges.KeyboardHidden |
           Android.Content.PM.ConfigChanges.Orientation)]
        public class BluetoothChat : Activity
    

    However, I did not test variations of this procedure or define any real CustomTheme attributes.

    0 讨论(0)
提交回复
热议问题