ActionBarSherlock: changing homeAsUpIndicator doesn't work

文章摘自stackoverflow上的一个帖子,解决了actionBar上换home图标左侧的“<”不起作用的问题。

原文如下:

Ask:

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>

Answer:

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.



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值