Custom Control (iv) Custom Click effect button

Source: Internet
Author: User

This section customizes the rounded Rectangle button with the click Effect.
features :
1.button Click to change color
2. The above text is also click Discoloration
3.button shape is rounded rectangle
4.button has a gradient effect

It is divided into five main steps :
First you need to create a drawable directory (pixel-independent drawable) in the Res directory.
1. Set the button's normal state

Button_shape_normal.xml<?xml version= "1.0" encoding= "Utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"android: Shape="Rectangle">       <!--set to rectangular--    <corners Android:radius="3DP"/> <!--set Rounded rectangle radius --    <gradientandroid:angle="android:endcolor" = "#cccccc"  Android:startcolor="#acacac"/>                           <!--Specify a color gradient (starting color, ending color, gradient direction) --</shape>

2. Set Button click Status

Button_shape_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="3DP"/> <!--set Rounded rectangle radius --    <gradientandroid:angle="android:endcolor" = "#cccccc "android:startcolor=" #acacac "/>                           <!--Specify a color gradient (starting color, ending color, gradient direction) --</shape>

3. Set the selector of the button

Button_shape_selector.xml<?xml version= "1.0" encoding= "Utf-8"?><selector xmlns:android="Http://schemas.android.com/apk/res/android" >    <item android:drawable="@drawable/button_shape_normal"android: state_pressed="false"/>            <item android:drawable="@drawable/button_shape_pressed"Android:state_ Pressed="true"/>        </selector>

4. Set the text color selector

//button_text_color.xml<?xml version= "1.0" encoding= "Utf-8"?  <selector  xmlns:android  = "http://schemas.android.com/apk/res/android" ;  <item   android:state_pressed  = android:color  = "#ffffff" />  < item  android:state_pressed  = "true"  android:color  =" #556699 "/>  </selector ;   

5. Reference the resource you just created in the button property

<Button        android:id="@+id/button"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:text="wangjiang"        android:textSize="16sp"        android:background="@drawable/button_shape_selector"         android:textColor="@drawable/button_text_color"/>

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Custom Control (iv) Custom Click effect button

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.