Android Custom view Focal state does not work

I am trying to create a custom background selector for my ExpandableListView. It works great for all but focused states. I cannot determine which row is currently focused. Here is the code:

im_selector.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_focused="true" android:drawable="@drawable/list_selector_background_focus" /> <item android:state_pressed="true" android:drawable="@drawable/list_selector_background_pressed" /> <item android:drawable="@drawable/list_bg" /> </selector> 

my list in layout file

 <ExpandableListView android:id="@+id/android:list" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:scrollbars="horizontal" android:layout_below="@id/top_bar" android:layout_marginBottom="45px" android:divider="#00000000" android:cacheColorHint="#00000000" android:listSelector="@layout/im_selector" android:focusable="true" /> 
+6
android
source share
1 answer

When you use touch mode with a list, the selected attribute changes, not focused. This is why for listviews you have to add a line like this in the selector:

 <item android:state_selected="true" android:drawable="@drawable/list_selector_background_focus" /> 
+8
source share

All Articles