Android: Entire ListView changes color on focus, not just ListView child item

后端 未结 1 1225
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-17 00:30

I am trying to apply a selector to a ListView to make it easy for those without touch screens to navigate my app. The thing is, by applying the selector to the ListView, it

相关标签:
1条回答
  • 2020-12-17 01:16

    The reason you're seeing the focused colour being applied to the whole list is because you have directly referenced a colour value for the focused and pressed states. There is a known bug in Android v2.3 and below where the colour drawable doesn't honour its bounds in these circumstances.

    To fix this issue you can create a shape drawable using the desired colours and reference that instead.

    e.g define the shape in 'drawables/list_selector_focused.xml' as:

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
           android:shape="rectangle">
    
        <solid android:color="@color/green" />
    
    </shape>
    

    And then reference that in the selector:

    <item android:state_focused="true"
          android:state_selected="true"
          android:state_pressed="false"
          android:drawable="@drawable/list_selector_focused" />
    
    0 讨论(0)
提交回复
热议问题