Custom title bar without padding (Android)

I was struggling with this same issue and now I have the answer!

As you probably have seen several places, you need to create a themes.xml resource:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MyTheme" parent="android:Theme">
            <item name="android:windowTitleSize">44dip</item>
            <item name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground</item>
    </style>
</resources>

Note it is not often mentioned in the sites talking about custom title bars you need to select this theme at the view, activity, or application level. I do it at the application level by adding android:theme property to the application:

  <application android:icon="@drawable/icon"
               android:label="@string/app_name"
               android:theme="@style/MyTheme">

You also need a styles.xml to define that WindowTitleBackgroundStyle. Unlike the various versions of this file I have seen floating aroung the web, I have added one additional line to the file that sets the padding to 0 which gets rid of the padding you are complaining about:

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <style name="WindowTitleBackground">
        <item name="android:background">@android:color/transparent</item>
        <item name="android:padding">0px</item>
    </style>
</resources>

Leave a Comment