How to remove blue glow from Sherlock action bar m

2019-02-19 18:57发布

Does anybody know how to remove this annoying blue glow that surrounds action bar menu item that is pressed?

enter image description here

Thanks, Mladjo

1条回答
够拽才男人
2楼-- · 2019-02-19 19:39

Yes, you can overwrite ...

android:actionBarItemBackground 

... that defines a drawable resource for each action item's background. E.g.

<style name="CustomActivityTheme" parent="@android:style/Theme.Holo">
    <item name="android:actionBarItemBackground">@drawable/ab_item_background</item>
</style>

Check the documentation here.

Note: if you want to support Android versions with API level less than 14 you have to include the support package and ActionBarSherlock (ABS) in your app. Afterwards you need to set the background for both - Android standard and ABS:

<style name="CustomActivityTheme" parent="@android:style/Theme.Holo">
    <item name="android:actionBarItemBackground">@drawable/ab_item_background</item>
    <item name="actionBarItemBackground">@drawable/ab_item_background</item>
</style>

Instead of a drawable you could also use a color, e.g.:

    <item name="actionBarItemBackground">@color/myColorDefinition</item>

p.s. ... or best, use a state drawable:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

  <item android:drawable="@drawable/button_pressed"
        android:state_pressed="true" />

  <item android:drawable="@drawable/button_default" />

</selector> 
查看更多
登录 后发表回答