Making a LinearLayout act like an Button

前端 未结 10 2091
无人及你
无人及你 2020-11-29 19:09

I have a LinearLayout that I\'ve styled to look like a button, and it contains a few text/ImageView elements. I would like to make the whole

10条回答
  •  臣服心动
    2020-11-29 19:29

    If you want add the Android default background behavior to make a Layout acts like a "clikable" View, set on the targeted Layout:

    API 11+ (Pure Android):

    android:background="?android:attr/selectableItemBackground"
    

    API 7+ (Android + AppCompat Support Library):

    android:background="?attr/selectableItemBackground"
    

    Any API:

    android:background="@android:drawable/list_selector_background"
    

    Answers above still true but didn't help me for just add the default pressed and released UI state (like in a ListView for instance).

提交回复
热议问题