how to change selected list item background, android

后端 未结 2 387
不知归路
不知归路 2021-01-03 13:34

I have two ListView\'s in my Activity, when i select one from first List data will reflected to other list. I have done this part, its

相关标签:
2条回答
  • 2021-01-03 13:53

    Just set in your main layout of list item view

    style="?attr/SelectableItemBackground"
    
    0 讨论(0)
  • You can do this by below -

    Set the android:listSelector="@drawable/selection" to your ListView's xml attribute. And, in your selection.xml contains the selector which will hold the change when you select any item from listview.

    selection.xml

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_focused="true" 
            android:state_pressed="false"
            android:drawable="@color/android_green" />
        <item android:state_focused="true" 
            android:state_pressed="true"
            android:drawable="@color/black_alpha" />
        <item android:state_focused="false" 
            android:state_pressed="true"
            android:drawable="@color/black_alpha" />
        <item android:drawable="@color/white_alpha" />
    </selector> 
    

    Have a look at this also.

    0 讨论(0)
提交回复
热议问题