First create a new Select.xml file under Drawable, with the following code:
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <selectorxmlns:android= "Http://schemas.android.com/apk/res/android" >3 <Itemandroid:state_pressed= "true"android:drawable= "@color/light_gray" /> 4 <Itemandroid:state_focused= "true"android:drawable= "@color/light_gray" /> 5 <Itemandroid:drawable= "@color/white"/>6 7 </selector>
Then create a new Color.xml file under the Values folder with the following code:
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Resources>3 <Colorname= "White">#FFFFFF</Color>4 <Colorname= "Light_gray">#efefef</Color>5 </Resources>
Finally, add the following code to the layout file:
1 < Relativelayout 2 Android:layout_width = "Match_parent" 3 android:layout_height= "Match_parent"4 android:background = "@drawable/select" 5 android:clickable= "true">
According to the above method, you can finally see the relativelayout background color is white, when clicked, the background color becomes light gray.
Android Settings click the color effect