Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ActionBarCompat支持库android:selectableItemBackground不工作_Android_Android Actionbar_Android Actionbar Compat - Fatal编程技术网

ActionBarCompat支持库android:selectableItemBackground不工作

ActionBarCompat支持库android:selectableItemBackground不工作,android,android-actionbar,android-actionbar-compat,Android,Android Actionbar,Android Actionbar Compat,我正在使用新的ActionBarCompat支持库。 当按下actionbar中的动作按钮时,它们的背景应该会发生变化,它适用于Android 4.3,但不适用于Gingerbread。 在姜饼中,如果我按下按钮,背景不会改变。 我甚至更改了选择器: <style name="Theme.MyCustomTheme" parent="@style/Theme.AppCompat.Light"> <item name="selectableItemBackground"&

我正在使用新的ActionBarCompat支持库。
当按下actionbar中的动作按钮时,它们的背景应该会发生变化,它适用于Android 4.3,但不适用于Gingerbread。 在姜饼中,如果我按下按钮,背景不会改变。 我甚至更改了选择器:

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

@可绘图/操作栏\项目\背景\选择器
同样,它与安卓4.3兼容,但与姜饼无关。
这是一个bug吗?

我发现了问题所在。您应该复制android选择器并对其进行修改

styles.xml

<style name="Theme.NewTransaction" parent="@style/Theme.AppCompat.Light.DarkActionBar">
        <item name="selectableItemBackground">@drawable/actionbar_item_bg_selector</item>
</style>
<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>

@可绘图/操作栏\项目\背景\选择器
actionbar\u item\u bg\u selector.xml

<style name="Theme.NewTransaction" parent="@style/Theme.AppCompat.Light.DarkActionBar">
        <item name="selectableItemBackground">@drawable/actionbar_item_bg_selector</item>
</style>
<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>

我认为我的问题与此评论有关:
即使这两个指向同一个资源,也有两个状态,因此drawable在退出pressed状态时会使自身失效