To set the background for app icon together with the homeAsUpIndicator (there is a common background for these two icons) you have to set android:actionBarItemBackground
item in the theme. The theme has to contain something like this (I assume that you use ActionBarSherlock):
<style name="MyTheme" parent="@style/Theme.Sherlock">
<!-- for ActionBarSherlock -->
<item name="actionBarItemBackground">@drawable/my_background</item>
<!-- for native ActionBar -->
<item name="android:actionBarItemBackground">@drawable/my_background</item>
</style>
Where the drawable drawable/my_background.xml
would be a StaleListDrawable, containing something like this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/my_background_pressed" />
<item
android:drawable="@drawable/my_background_normal" />
</selector>
To disable the background completely, you can set a transparent background, or value @null
in the theme might also work.
The theme item android:actionBarItemBackground
sets the background for app icon and homeAsUpIndicator. But it also sets the default background for menu items, overflow icon and background for title. These backgrounds can be overridden.
Menu items
To change the menu item background set a proper (android:)actionButtonStyle
in the theme like this:
<style name="MyTheme" parent="@style/Theme.Sherlock">
<item name="actionButtonStyle">@style/MyActionButtonStyle</item>
<item name="android:actionButtonStyle">@style/MyActionButtonStyle</item>
</style>
And MyActionButtonStyle
will contain something like this:
<style name="MyActionButtonStyle" parent="@style/Widget.Sherlock.ActionButton">
<item name="android:background">@drawable/my_background</item>
</style>
Overflow icon
And finally, to change the overflow icon background set a properandroid:actionOverflowButtonStyle
in the theme like this:
<style name="MyTheme" parent="@style/Theme.Sherlock">
<item name="actionOverflowButtonStyle">@style/MyOverflowButtonStyle</item>
<item name="android:actionOverflowButtonStyle">@style/MyOverflowButtonStyle</item>
</style>
And MyOverflowButtonStyle
will contain something like this:
<style name="MyOverflowButtonStyle" parent="@style/Widget.Sherlock.ActionButton.Overflow">
<item name="android:background">@drawable/my_background</item>
</style>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…