ListView selector not working with set ListViewItem background

I have a ListView that has a solid color selector set only.

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:id="@+id/assignmentSelectedItem" /> <ListView android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/assignmentsListView" android:layout_marginLeft="2dp" android:layout_marginRight="2dp" android:listSelector="@drawable/assignment_list_selector" /> </LinearLayout> 

assign_list_selector.xml -

 <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@android:color/white" /> <item android:drawable="@android:color/transparent"/> </selector> 

In ListView.Adapter for my list, I have items that have their background image background set to a specific color. My question is why does the selector not work at all when displaying the selected color for my list? If so, then any suggestion for use allows me to set the background color of the view.

+4
source share
1 answer

You can use the ListView property android:drawSelectorOnTop="true" in your layout .xml file to do a list view, to draw a selector above the list item and not below it.

If you have a background + list function, you can try a different approach: use a transparent list selector. And change your selector to use it as the background for the list item. for instance

 <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@android:color/white" /> <item android:drawable="@android:color/your_list_item_color"/> </selector> 
+12
source

Source: https://habr.com/ru/post/1440847/


All Articles