1. Create drawable under Project SRC
See document DEVELOP/API Guides/app Resources/drawable/shape drawable
Word: corners: angle; Gradient: Gradient; solid: fixed. Stroke: border--can be underlined
Rectangle: Rectangle; Dash: Dash gap: Gap.
2, copy instance code, file name (Gradient_box.xml, the following is the template)
<?XML version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" Android:shape= "Rectangle" > <corners android:radius= "5dip"/> <gradient android:startcolor= "# ff0000 " android:endcolor=" #00ff0000 "/> <solid android:color=" #ffffff "/> <stroke android: Width= "3dip" android:color= "#000000" android:dashgap= "5dip" android:dashwidth= "5dip"/> </shape>
3. Default state Function_greenbutton_normal.xml
<?xml version= "1.0" encoding= "Utf-8"?><shape xmlns:android= "http://schemas.android.com/apk/res/android" android:shape= "Rectangle" > <corners android:radius= "5dip"/> <solid android:color= "#ffffff"/> </shape>
4, press down state status Function_greenbutton_pressed.xml
<?XML version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" Android:shape= "Rectangle" > <corners android:radius= "5dip"/> <solid android:color= "#22000000" /> </shape>
5. Integration of two states in Shape_bg.xml
<?XML version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "Http://schemas.android.com/apk/res/android" > <item android:state_pressed= "true" android:drawable= "@drawable/function_greenbutton_pressed"/ > <!--pressed- <item android:state_focused= "true" android:drawable= "@drawable/function_ Greenbutton_pressed "/> <!--focused- <item android:drawable=" @drawable/function_greenbutton_ Normal "/> <!--default--></selector>
6. and use
Called Under the button box android:background= "@drawable/shape_bg".
Androidbuttonshape Shape Resource Code implementation