Search code examples
androidcustom-titlebarandroid-titlebar

Android custom title bar


I have been trying to do my custom title bar for a week.

I have tried approximately 30 suggestions to achieve that but nothing worked.

I get the you cannot combine custom titles with other title features error every time whatever I try. I can't get rid of this error. This driving me mad.

I have also tried to find a solution by looking for the error on Google. It also did not work.

Here is the code I've tried:

this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.my_custom_title);

I don't know how to achieve a custom title bar.

Much thanks for helps in advance.


Solution

  • Not the best way to do it in my opinion.

    You should do, in res/values/styles.xml, something like:

    <style name="AppBaseTheme" parent="...">
        <item name="android:actionBarStyle">@style/mActionBar</item>
    </style>
    
    <style name="mActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
            <item name="android:background">...</item>
            <item name="android:icon">...</item>
            <item name="android:titleTextStyle">...</item>
    </style>