Button custom (1)-shape

Source: Internet
Author: User

Requirement: Custom button. Use the System custom shape;

:

1. default status

2. Selected status

 

Implementation Analysis:

1. directory structure:

 

Code implementation:

1. button_normal.xml

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" >    <solid android:color="#ff007aff" />    <corners        android:bottomLeftRadius="6dp"        android:bottomRightRadius="6dp"        android:topLeftRadius="6dp"        android:topRightRadius="6dp" /></shape>

2. button_select.xml

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" >    <solid android:color="#FFD700" />    <corners        android:bottomLeftRadius="6dp"        android:bottomRightRadius="6dp"        android:topLeftRadius="6dp"        android:topRightRadius="6dp" /></shape>

Solid: solid, indicating Filling

Corners: rounded corner
Android: radius is the Radian of an angle. The larger the value is, the closer the angle is.

 

3. button_selector.xml

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:drawable="@drawable/button_select" android:state_focused="true"></item>    <item android:drawable="@drawable/button_select" android:state_pressed="true"></item>    <item android:drawable="@drawable/button_normal" android:state_focused="false" android:state_pressed="false"></item>    <item android:drawable="@drawable/button_normal" ></item></selector>

4. fragment_main.xml

<Relativelayout xmlns: Android = "http://schemas.android.com/apk/res/android" xmlns: Tools = "http://schemas.android.com/tools" Android: layout_width = "match_parent" Android: layout_height = "match_parent" tools: context = "com. JJC. demo. mainactivity $ placeholderfragment "> <button Android: Id =" @ + ID/button_test "Android: layout_width =" match_parent "Android: layout_height =" wrap_content "Android: background = "@ drawable/button_selector" Android: text = "Recommended combination" Android: textcolor = "@ Android: color/White"/> </relativelayout>

 

 

Code: http://pan.baidu.com/s/1ntBN5Df

Button custom (1)-shape

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.