How to remove blue glow from Sherlock action bar menu item?

前端 未结 1 2006
孤街浪徒
孤街浪徒 2021-01-15 09:03

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

\"e

相关标签:
1条回答
  • 2021-01-15 09:50

    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> 
    
    0 讨论(0)
提交回复
热议问题