ListView element with list_selector_background as LayerList drawable

If we use ListView or ExpandableListView, the default background is @android:drawable/list_selector_background . I have an ExpandableListView that shows data grouped by date. I like the list_selector_background state list, which draws and wants to preserve behavior for different states. But for the weekend (for some list items) I would like to define my own background. But these elements should still use drawings for different states defined through list_selector_background. I saw various inappropriate answers. Most of them say that I should define my own list of states. The list_selector_background.xml defines, in addition to different values ​​for different states, <item android:state_window_focused="false" android:drawable="@color/transparent" />

So, I thought that I could define my own list of states and just change the transparency to the desired color. The problem is that the drawings used for states are not publicly available. I really want to stay close to the android style, so I don't want to write my own list of states with the ability to draw for states.

At the end, I wrote a solution using a list of layers.

 <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@color/DarkBlue" android:id="@+id/background" /> <item android:drawable="@android:drawable/list_selector_background" android:id="@+id/list_selector_background" /> </layer-list> 

This perfectly matches the desired behavior with one exception: /. I have my own background and the element responds with the drawable defined in list_selector_background for print events. But somehow the focused state doesn't use the drawable defined by list_selector_background ( <item android:state_focused="true" android:drawable="@drawable/list_selector_background_focus" /> )

So, kindly ask, can anyone imagine why a focused state doesn't work? I am developing a level 8 API. If you need more information that I would like to publish. Thanks

+4
source share

All Articles