3

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.

JustWork
  • 1,944
  • 3
  • 22
  • 34

2 Answers2

1

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>
Romain Pellerin
  • 2,470
  • 3
  • 27
  • 36
  • What is the best way in your opinion? – JustWork Jun 28 '13 at 03:20
  • 1
    To use styles.xml as I wrote – Romain Pellerin Jun 28 '13 at 16:54
  • How to customize (add textview, imageview etc.) with this way? – JustWork Jun 29 '13 at 00:27
  • Are you talking about the left icon and the associated title? You should also read this http://developer.android.com/guide/topics/ui/actionbar.html – Romain Pellerin Jun 29 '13 at 03:35
  • I am talking about putting search, refresh icons and handling their click events. – JustWork Jun 29 '13 at 18:32
  • Ok so read this http://developer.android.com/guide/topics/ui/actionbar.html and this http://thedevelopersinfo.wordpress.com/2009/10/29/handling-options-menu-item-selections-in-android/ – Romain Pellerin Jun 30 '13 at 04:58
  • I am wondering what's the main difference between ActionBar and TitleBar. How to decide to use which is better. Maybe it's mentioned in that article. If it's not, I will ask it :) Thanks for your helps. By the way, I changed color of title bar with code you provided. But it changed whole color system. I don't know why. – JustWork Jun 30 '13 at 05:09
  • TitleBar is the old title bar used before Android 3.0, now it's called ActionBar and it's pretty different. Use the android:background inside your ActionBar style, not your application style, as I wrote it. – Romain Pellerin Jun 30 '13 at 09:15
0

I recently faced the same error while implementing a custom title bar..."you cannot combine custom titles with other title features"

According to You cannot combine custom title with other title features, Holo's title bar is displayed if the project uses Holo theme.

I stripped my project of all code that uses Holo, and after that my custom title bar displayed.

Community
  • 1
  • 1
Shuaib
  • 779
  • 2
  • 13
  • 47