Androidbuttonshape Shape Resource Code implementation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.