4

I'm want to change the up icon with applying the following style to my activity, but it doesn't work and but I still get the default black '<' icon.

Can anyone find out what is missing here?

<style name="AppTheme.ActionBar" parent="@style/Theme.Sherlock.Light">
    <item name="actionBarStyle">@style/actionBarStyle</item>
    <item name="android:actionBarStyle">@style/actionBarStyle</item>
</style>

<style name="actionBarStyle" parent="@style/Widget.Sherlock.Light.ActionBar.Solid">
    <item name="android:background">@drawable/header_bar</item>
    <item name="background">@drawable/header_bar</item>

    <item name="android:homeAsUpIndicator">@drawable/up_indicator</item>
    <item name="homeAsUpIndicator">@drawable/up_indicator</item>
    <item name="android:displayOptions">homeAsUp|showHome</item>
    <item name="displayOptions">homeAsUp|showHome</item>

</style>
kiritsuku
  • 52,967
  • 18
  • 114
  • 136
Gal Ben-Haim
  • 17,433
  • 22
  • 78
  • 131

1 Answers1

21

If I remember correctly, I worked around this issue by moving you should move the android:homeAsUpIndicator and homeAsUpIndicator elements into the main theme declaration. In other words, try:

<style name="AppTheme.ActionBar" parent="@style/Theme.Sherlock.Light">
    <item name="actionBarStyle">@style/actionBarStyle</item>
    <item name="android:actionBarStyle">@style/actionBarStyle</item>
    <item name="android:homeAsUpIndicator">@drawable/up_indicator</item>
    <item name="homeAsUpIndicator">@drawable/up_indicator</item>
</style>

<style name="actionBarStyle" parent="@style/Widget.Sherlock.Light.ActionBar.Solid">
    <item name="android:background">@drawable/header_bar</item>
    <item name="background">@drawable/header_bar</item>
    <item name="android:displayOptions">homeAsUp|showHome</item>
    <item name="displayOptions">homeAsUp|showHome</item>
</style>

Not sure whether I also had to move up the displayOptions, but you may want to give that a go too in case above doesn't work right away.

By the way, I find naming a style AppTheme.ActionBar and then inheriting from Theme.Sherlock.Light rather confusing. If it were an ActionBar specific style, I would've expected something like Widget.Holo.Light.ActionBar (or any of the other widget styles) as the parent. If it's your main theme, I'd name it accordingly. Up to you of course.


Edit: Updated answer after Jake's comment.

MH.
  • 45,303
  • 10
  • 103
  • 116
  • 3
    Moving it into the theme isn't a workaround, it's the appropriate location for this. The `displayOptions` should remain inside the action bar style declaration. – Jake Wharton Nov 01 '12 at 01:21
  • Thanks. This works great. My only problem is the image i want to use is bigger than the default up image. The system adds padding the same width as the custom up image, even when its not showing... any ideas? – speedynomads Oct 25 '13 at 14:29
  • Thanks it helped and worked i was scratching my head over it from last two days – Iftikar Urrhman Khan Mar 03 '14 at 13:28
  • @JakeWharton, your comments are lifesaving as ever! Admiring your job – Dmitry Gryazin Aug 08 '14 at 22:52