how to change font color in selected/focused ListView items?

前端 未结 5 1472
心在旅途
心在旅途 2020-12-13 02:00

I am struggling with this which apparently is a very simple effect but incredibly haven\'t found any intutitive way for doing it in Android.

I have a ListView and I

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-13 02:34

    Neither of these are possible answers when your ListView is compromised of a layout that has multiple views. You need to set your child views to:

    android:duplicateParentState="true"
    

    Now you can use the methods others have described above to declare your TextViews' colors using a selector such as:

    android:textColor="@drawable/my_row_selector"
    

    and I'm sure you're aware, but the selector can be as simple as:

    
    
        
        
    
    

    As you can see, @color values are allowed. Hope this helps.

    Also - android:state_pressed is used in conjunction with the AdapterView.OnItemClickListener.

提交回复
热议问题