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