Apps for Android Graphics state combination (note)

Source: Internet
Author: User

Purpose: Create a button when the button has a different shape state for the button

Under Res drawable-hdpi save button Initial state left.png and button pressed state picture rigth.png.

Drag the picture file to the created folder drawable-hdpi

Create a generic XML file with the new drawing state combination step

Drawable_change→new→other ... →xml→xml File

Note: Change the left_rigth.xml to Left_right. XML

Fill in the following code in Left_right.xml

<?xml version= "1.0" encoding= "UTF-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android >    <!--Press Status-    <item         android:state_pressed= "true"         android:drawable= "@ Drawable/left "/>        <!--default status--    <item         android:drawable=" @drawable/rigth "/></ Selector>

In Activity_main. XML to Code

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"    xmlns:tools= "http// Schemas.android.com/tools "    android:id=" @+id/container "    android:layout_width=" Match_parent "    Android : layout_height= "match_parent"    tools:context= "com.example.test.MainActivity"    tools:ignore= " Mergerootframe ">        <button                android:id=" @+id/button1 "        android:layout_width=" 30DP "        android: layout_height= "Wrap_content"        android:background= "@drawable/left_right"/>    <button                android: Id= "@+id/button2"        android:layout_width= "30DP"        android:layout_height= "Wrap_content"        android: layout_below= "@id/button1"        android:background= "@drawable/left_right"/> </RelativeLayout>

The test results are as follows:

Reprint Please specify source: http://blog.csdn.net/u010499449/article/details/42192383

Apps for Android Graphics state combination (note)

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.