Purpose: Create a button when the button has a different shape state for the button
Under Res drawable-hdpi save button Initial state left.png and button pressed state picture rigth.png.
Drag the picture file to the created folder drawable-hdpi
Create a generic XML file with the new drawing state combination step
Drawable_change→new→other ... →xml→xml File
Note: Change the left_rigth.xml to Left_right. XML
Fill in the following code in Left_right.xml
<?xml version= "1.0" encoding= "UTF-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android > <!--Press Status- <item android:state_pressed= "true" android:drawable= "@ Drawable/left "/> <!--default status-- <item android:drawable=" @drawable/rigth "/></ Selector>
In Activity_main. XML to Code
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools " android:id=" @+id/container " android:layout_width=" Match_parent " Android : layout_height= "match_parent" tools:context= "com.example.test.MainActivity" tools:ignore= " Mergerootframe "> <button android:id=" @+id/button1 " android:layout_width=" 30DP " android: layout_height= "Wrap_content" android:background= "@drawable/left_right"/> <button android: Id= "@+id/button2" android:layout_width= "30DP" android:layout_height= "Wrap_content" android: layout_below= "@id/button1" android:background= "@drawable/left_right"/> </RelativeLayout>
The test results are as follows:
Reprint Please specify source: http://blog.csdn.net/u010499449/article/details/42192383
Apps for Android Graphics state combination (note)