ListView item background via custom selector

前端 未结 10 1538
深忆病人
深忆病人 2020-11-22 08:19

Is it possible to apply a custom background to each Listview item via the list selector?

The default selector specifies @android:color/transparent for t

10条回答
  •  耶瑟儿~
    2020-11-22 08:59

    I've been frustrated by this myself and finally solved it. As Romain Guy hinted to, there's another state, "android:state_selected", that you must use. Use a state drawable for the background of your list item, and use a different state drawable for listSelector of your list:

    list_row_layout.xml:

    
    
    ...
    
    

    listitem_background.xml:

    
    
        
        
    
    

    layout.xml that includes the ListView:

    ...
    
    ...
    

    listitem_selector.xml:

    
    
        
        
    
    

提交回复
热议问题