Android: Custom Title Bar

I had the same issue as you.

The issue is with something you have in your style.

Try this out:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="My_Theme">
        <item name="android:windowTitleSize">35dp</item>
        <item name="android:windowTitleBackgroundStyle">@android:color/black</item>
    </style>
</resources>

First thing why are you using a custom title bar if your app has NoTitleBar? That is silly!

Needless to say, this is your problem and you must remove that flag.

Anyhow, the best way to add custom title bar is in xml only. This avoids your app double loading the title bar; which users will see.

../res/styles.xml

<resources>

   <style name="AppTheme parent="@style/android:Theme.Light">
      <item name="android:windowNoTitle">false</item>
      <item name="android:windowTitleSize">30dp</item
      <item name="android:windowTitleStyle">@layout/custom_title</item>
   </style>

</resources>

Then you dont need that code about requestAnything.


This one is the only one for me, which prevents the default-title before my custom title is initiated:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="CustomWindowTitleStyle">
        <item name="android:textColor">@android:color/transparent</item>
    </style>

    <style name="CustomTheme" parent="@android:style/Theme.Holo">
        <item name="android:windowActionBar">false</item>
        <item name="android:windowTitleBackgroundStyle">@android:color/transparent</item>
        <item name="android:windowTitleSize">50dp</item>
        <item name="android:windowTitleStyle">@style/CustomWindowTitleStyle</item>
    </style>

</resources>