Android Custom Control Skins

Source: Internet
Author: User

Android Custom Control Skins

For Android's own control, its appearance can only be said, and we usually see the Android application, a simple button is very beautiful, and even many buttons in the press when the appearance of a certain change, the user experience is very good. This involves the operation of the Android custom control property, as an example of implementing the custom button skin.

1. We want to customize the appearance state that will be implemented, can be a picture or a custom XML, this is we directly customize the color XML of different states, the new colors.xml in the values directory, the code is as follows:

Colors.xml

<?xml version= "1.0" encoding= "Utf-8"?><resources>    <color name="btn_no_pressed">#3300ffff</color>    <color name="btn_pressed">#33ffff00</color></Resources>

The name in the file can be custom named according to the project, and the value is in ARGB format.

2. To set the different states of the button that will be implemented, create a new Btn_bg.xml file in the drawable directory, type remember to select "Selector", the code is as follows:

Btn_bg.xml

<?xml version= "1.0" encoding= "Utf-8"?><selector xmlns:android="Http://schemas.android.com/apk/res/android" >    <item android:state_pressed="false" android:drawable="@color/btn_ No_pressed "></Item>    <item android:state_pressed="true" android:drawable="@color/btn_ Pressed "></Item></selector>

Android:state_pressed= "" Defines whether a control is pressed, a value of Boolean, a similar property you can try to learn by yourself, android:drawable= "" Defines the appearance of the control when it is in the appropriate state.

3. We can now apply the defined state to the layout file, with the following code:

Activity_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"    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=". Mainactivity ">     Button  android:id  =" @+id/mybtn " android:layout_width  =" Match_parent "  android:layout_height  =" wrap_content " android:text  =" click Me " android:background  =" @drawable/btn_bg "/> </relativelayout>

Once the above steps are done, you can run the application for debugging, which is just a simple example >~<

Android Custom Control Skins

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.