Default selector background in Clickable Views

前端 未结 9 1354
执念已碎
执念已碎 2020-12-23 02:15

I have some clickable views and I want to set the default available background that is present on list click (in ICS is a blue color). I have tried putting as background thi

9条回答
  •  佛祖请我去吃肉
    2020-12-23 02:35

    This works fine on api 11 and above. But as noted it wont work on previous versions.

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

    Here is a solution to have it run on all versions running android.

    1. Add the appropriate colors within the colors.xml which is located within your values folder. It should appear as such:

      #ffffff
      #7ecce8
      
    2. Create an xml selector file. Here I named it button_selection.xml

      
      
               
       
       
       
      
    3. Go to your view or button and set the newly created button_selection.xml as its background.

      android:background="@drawable/button_selection"
      

提交回复
热议问题