简体   繁体   中英

Android - How do I make the actionbar “up icon” pressed color show through the png?

On my ActionBar the "up icon" and logo during the "pressed" state shows a bright red border (as I want). But it doesn't show the bright red through the image's transparency, so the image still shows the ActionBar normal background color. The image is transparent and works in the default theme. But when using the ActionBar Theme Generator, I can't get it to work. However, the Action buttons on the right behave properly.

I can get the light red to disappear completely by making the pressed state transparent, so I think I'm styling the item underneath the image, and not the image (or its immediate container?). I'm not using Sherlock. I'm targeting min sdk 16.

My theme xml:

...
<item name="android:actionBarItemBackground">@drawable/red_selectable_background</item>

My red_selectable_background.xml:

<selector xmlns:android="http://schemas.android.com/apk/res/android"
    android:exitFadeDuration="@android:integer/config_mediumAnimTime" >
    <item android:state_pressed="false" android:state_focused="true" android:drawable="@android:color/transparent" />
    <item android:state_pressed="true" android:drawable="@drawable/red_pressed_background" />
    <item android:drawable="@android:color/transparent" />
</selector>

My red_pressed_background.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <solid android:color="@color/blood_red" />
</shape>

My Color:

<color name="blood_red">#a00f0f</color>

I blew away my styles and generated fresh. I think what I was missing was when I merged the ActionBar theme with the Holo theme (both generated), I didn't properly merge the generated top-level ActionBar theme. Now I don't need any of the custom stuff I wrote before.

Basically I just had to merge the following items into my theme that inherits from android:Theme.Holo:

<item name="android:actionBarItemBackground">@drawable/selectable_background_xxx</item>
<item name="android:popupMenuStyle">@style/PopupMenu.xxx</item>
<item name="android:dropDownListViewStyle">@style/DropDownListView.xxx</item>
<item name="android:actionBarTabStyle">@style/ActionBarTabStyle.xxx</item>
<item name="android:actionDropDownStyle">@style/DropDownNav.xxx</item>
<item name="android:actionBarStyle">@style/ActionBar.Transparent.xxx</item>
<item name="android:actionModeBackground">@drawable/cab_background_top_xxx</item>
<item name="android:actionModeSplitBackground">@drawable/cab_background_bottom_xxx</item>
<item name="android:actionModeCloseButtonStyle">@style/ActionButton.CloseMode.xxx</item>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM