Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot combine custom titles with other title features

Tags:

android

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

    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.maintitlebar);

The code is in the onCreate() for my class which extends ListActivity. My manifest XML file shows the default AppTheme for the application:

     android:theme="@style/AppTheme"

I have updated styles.xml to be:

<resources>
   <style name="AppTheme" parent="android:Theme.Light" >
    <item name="android:windowNoTitle">true</item>
   </style>   
</resources>

This seems to be in accordance with the main posts on this error message. I have also cleaned the build, yet I am still getting the above error message. Has anybody any idea what is causing the clash?

like image 976
Marion McKelvie Avatar asked Nov 02 '12 14:11

Marion McKelvie


4 Answers

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.

like image 75
an00b Avatar answered Nov 15 '22 06:11

an00b


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

like image 23
Vladimir Avatar answered Nov 15 '22 04:11

Vladimir


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

like image 13
user2618844 Avatar answered Nov 15 '22 06:11

user2618844


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>
like image 2
David Conlisk Avatar answered Nov 15 '22 06:11

David Conlisk