ActionBarCompat支持库的android:selectableItemBackground不工作工作、ActionBarCompat、android、selectableItemBackg

由网友(不在作践自己。)分享简介:我使用的是新的ActionBarCompat支持库。在动作条的操作按钮应该改变他们的背景时,pressed,它的工作原理与Android 4.3,但不与姜饼。在姜饼如果我$一个按钮p $ PSS不会改变的背景。我甚至改变了选择:I'm using the new ActionBarCompat support...

我使用的是新的ActionBarCompat支持库。 在动作条的操作按钮应该改变他们的背景时,pressed,它的工作原理与Android 4.3,但不与姜饼。 在姜饼如果我$一个按钮p $ PSS不会改变的背景。 我甚至改变了选择:

I'm using the new ActionBarCompat support library. The action buttons in the actionbar should change their background when pressed, It works with Android 4.3 but not with Gingerbread. In Gingerbread if I press on a button it will not change the background. I even changed the selector:

<style name="Theme.MyCustomTheme" parent="@style/Theme.AppCompat.Light">
    <item name="selectableItemBackground">@drawable/actionbar_item_bg_selector</item>
</style>

和再次,它正在与Android 4.3,但不与姜饼。 这是一个错误?

And again it is working with Android 4.3 but not with Gingerbread. Is this a bug ?

推荐答案

我想通了什么问题。您应该复制Android的选择和修改。

I figured out what was the problem. You should copy the android selector and modify it.

styles.xml

<style name="Theme.NewTransaction" parent="@style/Theme.AppCompat.Light.DarkActionBar">
        <item name="selectableItemBackground">@drawable/actionbar_item_bg_selector</item>
</style>

actionbar_item_bg_selector.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_window_focused="false" android:drawable="@color/transparent" />

    <!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->
    <item android:state_focused="true"  android:state_enabled="false" android:state_pressed="true" android:drawable="@drawable/list_selector_background_disabled" />
    <item android:state_focused="true"  android:state_enabled="false"                              android:drawable="@drawable/list_selector_background_disabled" />
    <item android:state_focused="true"                                android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition" />
    <item android:state_focused="false"                               android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition" />
    <item android:state_focused="true"                                                             android:drawable="@drawable/list_selector_background_focused" />
    <item android:drawable="@color/transparent" />

</selector>

我想我的问题是有关此评论: 虽然这两个指向同一个资源,有两种状态,以便在绘制将现身pressed状态时无效本身。的

I think my problem was related to this comment: Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state.

阅读全文

相关推荐

最新文章