How to create a state list drawable for my ListView items?

前端 未结 1 653
情话喂你
情话喂你 2021-01-26 15:13

I have a custom ListView selector which draws on top of a ListView. It works fine, but I want the text inside of the listview to turn white. How can I do that?

&         


        
相关标签:
1条回答
  • 2021-01-26 16:10

    You need to apply specific color or selector to each list item.

    I have something like this (abreviated)

    layout/dash_item.xml

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                 style="@style/DashboardListItem">
       ... Your text components etc ....
    

    color/dashboard_selector.xml

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

    values/style.xml

     <style name="DashboardListItem">
            <item name="android:background">@color/dashboard_selector</item>
     </style>
    

    You probably will need to play with it to figure where exactly apply things. It can probably be simplified. Anyway, it's just a direction since I don't know your specific requirements.

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