ListView row selector at API level 10?

The target changes the background color of the selected ListView row. Which I succeed at API level 13 and 16. But the same code did not pass at API level 10 (2.3.3). No exception is thrown, but does not change color.

This is what I have tried;

list_row.xml

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/row_bg_colors" android:orientation="vertical" android:padding="8dp" > <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/app_name" android:textSize="25sp" /> </LinearLayout> 

row_bg_colors.xml

 <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <!-- selected --> <item android:drawable="@color/lightBlue" android:state_selected="true"/> <item android:drawable="@color/lightBlue" android:state_activated="true"/> <item android:drawable="@color/lightBlue" android:state_focused="true"/> <item android:drawable="@color/lightBlue" android:state_checked="true"/> <!-- default --> <item android:drawable="@drawable/unit_bg"/> </selector> 

A very simple adapter that has nothing to do with the background. Classical ListView object (not extended). singleChoice in ListView in activity xml file.

There is no compatibility warning.

So, is there an unsupported feature that I am missing? Or what?

+4
source share
1 answer

Also add a list selector to the list. I.e:

 <ListView android:listSelector="@drawable/row_bg_colors" /> 

And also leave row_bg_colors as the background for the line layout line.

Hope this helps.

+1
source

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


All Articles