ListView item won't stay “selected”

后端 未结 10 1310
暗喜
暗喜 2020-12-10 05:50

I want to change the background of a listview item when the user clicks it. Kind of like the Honeycomb settings page (Although I\'m not dealing with just settings so I\'m no

10条回答
  •  遥遥无期
    2020-12-10 06:38

    Hope this help,

    1.- Create a shape file for focused item: \drawable\list_selector_focused.xml

        
    
         
    
    
    

    2.- Create a shape file for pressed item: \drawable\list_selector_pressed.xml

        
    
        
    
    
    

    3.- Create list selector file: \drawable\list_selector.xml

        
    
        
        
        
    
    
    

    4.- Add this attribute to your ListView in the layout file:

     android:choiceMode="singleChoice"
     android:listSelector="@drawable/list_selector"
    

    You can use colors instead of gradient shapes,

提交回复
热议问题