I cannot figure out how to change the action bar items "onPressed" color on Android. I'm not talking about the action bar background color but about the blue over state. How can I change the color of this or at least get rid of it? For instance the App Icon with the homeAsUpIndicator.
I tried to change the action bar style and also the menu item style but nothing worked.
Thanks
EDIT Here is my implementation so far:
My style xml:
<style name="Theme.AppTheme" parent="@android:style/Theme.Holo">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="android:selectableItemBackground">@android:color/transparent</item>
<item name="android:windowEnterAnimation">@anim/fadein</item>
<item name="android:windowExitAnimation">@anim/fadeout</item>
<item name="android:actionBarItemBackground">@android:color/transparent</item>
</style>
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">@drawable/actionbarheader</item>
<item name="android:backgroundStacked">@drawable/actionbarheader</item>
<item name="android:backgroundSplit">@drawable/actionbarheader</item>
<item name="android:titleTextStyle">@style/ActionBarTitle</item>
<item name="android:actionBarItemBackground">@android:color/transparent</item>
<item name="android:actionButtonStyle">@style/MyActionButtonStyle</item>
<item name="android:homeAsUpIndicator">@drawable/actionbarlogo</item>
<item name="android:icon">@drawable/app_icon</item>>
</style>
<style name="ActionBarTitle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textSize">20sp</item>
</style>
<style name="MyActionButtonStyle" parent="@android:style/Widget.Holo.Light.ActionButton">
<item name="android:background">@android:color/transparent</item>
</style>
Then I have a drawable for the actionbarogo:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/actionbarlogo_on" android:state_pressed="true"/>
<item android:drawable="@drawable/actionbarlogo_on" android:state_focused="true"/>
<item android:drawable="@drawable/actionbarlogo_off"/>
</selector>
My menu xml for the action bar items:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/ContactsMode"
android:icon="@drawable/actionbarcontacts"
android:title="@string/contacts"
android:orderInCategory="100"
android:showAsAction="always"
android:background="@android:color/transparent" />
</menu>
and finally, the item's drawable:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/actionbarcontacts_on" android:state_pressed="true"/>
<item android:drawable="@drawable/actionbarcontacts_on" android:state_focused="true"/>
<item android:drawable="@drawable/actionbarcontacts_off"/>
</selector>
Here is how I create the Menu Items for the ActionBar:
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
actionBar.setIcon(R.drawable.actionbarlogo);
return true;
}
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem item= menu.findItem(R.id.ContactsMode);
if(ContactsButton)
item.setVisible(true);
else
item.setVisible(false);
return true;
}
Fixed it. There was a parent activity changing the theme in the onCreate method...
I didn't know that you could set the theme programmatically within the activity with:
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):Where the drawable
drawable/my_background.xml
would be a StaleListDrawable, containing something like this: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:And
MyActionButtonStyle
will contain something like this:Overflow icon
And finally, to change the overflow icon background set a proper
android:actionOverflowButtonStyle
in the theme like this:And
MyOverflowButtonStyle
will contain something like this: