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, below is 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".
android button Shape shape resource code implementation