Android listview item background change

前端 未结 3 582
借酒劲吻你
借酒劲吻你 2021-01-18 07:27

i have a android listview. i want to change listview item background when i click one listview item.

and then previous selected item must go back to default backgrou

3条回答
  •  情话喂你
    2021-01-18 08:06

    You can change the ListView item colour on clicking it like below. Follow these steps.

    (Remember, This is for Custom List View)

    1. Create an XML file in Drawable Folder as Below:

      
      
      
      

      Choose your own resources.

    2. While implementing Custom ListVIew, you'll have additional layout for Custom List Item design. Below is such an Example.

      
      
      
      

    In Above code I have put the set the XML file from Step 1 as "background" attribute. This will work as you want to.

    Additionally if you want to change the text colour on ListItem selection as well, use below XML code and set that XML file as "TextColor" attribute.

    
    
    
        
        
        
        
    
    
    

    The code above will change the text color to while on selection and revert to original when unclicked.

提交回复
热议问题