Make linear layout selectable like a list item in a list view (Android)

后端 未结 3 1082
太阳男子
太阳男子 2021-02-02 11:01

I know how to add an onClick listener to a LinearLayout to make the whole layout a click target, but I\'d like to have the LinearLayout get highlighted when tapped just like a l

3条回答
  •  一生所求
    2021-02-02 11:41

    I ran into this and this is what I came up with. In your layout, set the background to a drawable resource:

     
    ...
    
    

    Then in drawable, add clickable.xml as so:

    
    
          
    
    

    Then it's up to you whether or not you want to add a click handler in your activity.

提交回复
热议问题