14

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?

Marion McKelvie
  • 424
  • 1
  • 5
  • 15
  • Possible duplicate of [Try to use Window.FEATURE\_CUSTOM\_TITLE but got Exception:You cannot combine custom titles with other title feature..](http://stackoverflow.com/questions/2686556/try-to-use-window-feature-custom-title-but-got-exceptionyou-cannot-combine-cust) – Code-Apprentice Aug 27 '16 at 19:35

6 Answers6

32

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.

Community
  • 1
  • 1
an00b
  • 11,338
  • 13
  • 64
  • 101
  • 2
    I'm having the same issue, but not found any solution. what should I need to do? (I did it with adding this android:theme="@android:style/Theme" ) – Mustafa Güven Mar 26 '13 at 13:53
  • 1
    I think the issue here is a conflict with some of Android's themes (like Holo) which are only used in recent sdks. The correct solution would be to disable this theme setting parent style to e.g. android:Theme (like in user2618844's post). – User Oct 14 '13 at 10:56
  • 4
    Adding this to Custom Style solved the issue: false – Jasper Dec 26 '14 at 10:13
24

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

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
Vladimir
  • 514
  • 3
  • 6
13

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

legrandviking
  • 2,348
  • 1
  • 22
  • 29
user2618844
  • 352
  • 3
  • 13
  • 2
    This change eliminated the error and displayed my custom window title, but also substantially changed the look and feel of the rest of my app. – pettys Jan 07 '14 at 16:05
2

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>
David Conlisk
  • 3,387
  • 4
  • 33
  • 39
0

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

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.

NightOwl888
  • 55,572
  • 24
  • 139
  • 212
King Coffee
  • 47
  • 4
  • 9