Android Custom Button control implements buttons Click Color _android

Source: Internet
Author: User

The effect diagram looks like this:

Shape Style: ( New in drawable--"new--" drawable resource file Add item in parent label selector)

<?xml version= "1.0" encoding= "Utf-8"?> <selector xmlns:android=
"http://schemas.android.com/apk/res/" Android ">
<item android:state_pressed=" true ">
<shape android:shape=" Rectangle ">
< Solid android:color= "#73c4f3"/>
<stroke android:width= "2DP" android:color= "#ffffff"/>
< Corners android:radius= "20DP"/>
<padding android:bottom= "5DP" android:left= "10DP" android:right= "10DP" android:top= "5DP"/>
<gradient android:angle= "270" android:endcolor= "#8accf2" android:startcolor= "# 8accf2 "android:type=" Sweep "/>
</shape>
<shape>
<solid android:color=" #3fb3f6 " >
<stroke android:width= "2DP" android:color= "#ffffff"/>
<corners android:radius= "20DP"/>
<padding android:bottom= "5DP" android:left= "10DP" android:right= "10DP" android:top= "5DP"/>
</ shape>
</item>
</selector>

Second, style style:

<style name= "Rectangle" >
<item name= "Android:layout_width" >match_parent</item>
< Item Name= "Android:layout_height" >wrap_content</item>
<item name= "Android:textsize" >15sp</ item>
<item name= "Android:textcolor" > #ffffff </item>
<item name= "Android:background" > @drawable/buttonclickstyle</item>
</style>

Three, Button control calls the style style:

<?xml version= "1.0" encoding= "Utf-8"?> <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"
android:paddingbottom= "@dimen/activity_vertical_margin"
android: paddingleft= "@dimen/activity_horizontal_margin"
android:paddingright= "@dimen/activity_horizontal_margin"
android:paddingtop= "@dimen/activity_vertical_margin"
tools:context= " Com.example.ly.blogtest.MainActivity ">
<button
android:id=" @+id/button "
style=" @style Rectangle "
android:text=" @string/btn1 "/>
</RelativeLayout>

----------------------------------button Click to change color-----------------------------------------------------

----------------------------------Item Property Tag------------------------------

Android:state_pressed whether to press, like a button to touch or click.

Android:state_focused whether to get the focus, for example, the user selects a text box.

android:state_hovered cursor is hovering, usually the same as focused state, which is a new feature of 4.0

Android:state_selected is selected, it is not exactly the same as the focus state, when a list view is selected, each subassembly inside it may be selected by the arrow keys.

Whether the Android:state_checkable component can be check. For example: RadioButton can be check.

Android:state_checked was checked, such as: A RadioButton can be check.

Android:state_enabled can accept touch or click events

Android:state_activated is activated.

Android:state_window_focused

If the application is in the foreground, the application is not in the foreground when the notification bar is pulled down or a dialog box pops up.

Note: If you have more than one item, the program will automatically match from top to bottom, and the first match will be applied. (not through Best Bets)

If an item does not have any state description, it can be matched by any one of the states.

----------------------------------Item Property Tag------------------------------

The above is a small set to introduce the Android Custom button control buttons Click to change color, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.