Skip to content Skip to sidebar Skip to footer

Actionbarcompat Support Library Android:selectableitembackground Not Working

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 Gingerbre

Solution 1:

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

styles.xml

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

actionbar_item_bg_selector.xml

<selectorxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid: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. --><itemandroid:state_focused="true"android:state_enabled="false"android:state_pressed="true"android:drawable="@drawable/list_selector_background_disabled" /><itemandroid:state_focused="true"android:state_enabled="false"android:drawable="@drawable/list_selector_background_disabled" /><itemandroid:state_focused="true"android:state_pressed="true"android:drawable="@drawable/list_selector_background_transition" /><itemandroid:state_focused="false"android:state_pressed="true"android:drawable="@drawable/list_selector_background_transition" /><itemandroid:state_focused="true"android:drawable="@drawable/list_selector_background_focused" /><itemandroid:drawable="@color/transparent" /></selector>

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.

Post a Comment for "Actionbarcompat Support Library Android:selectableitembackground Not Working"