Android graphics status Combination Application (Note), android graphics
Purpose: To create a button that has different shapes
In the res drawable-hdpi leleft.pngand the status picture rigth.png.
Drag the image file to the created folder drawable-hdpi.
Create a common XML file and create a graphical state combination step:
Drawable_change → New → Other... → XML File
Note: Change Left_Rigth.XML to left_right.XML.
Enter 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/riable"/> </selector>
Code in activity_main.XML
<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:
Reprinted please indicate the source: http://blog.csdn.net/u010499449/article/details/42192383