Click to change the implementation of the image, click to change the implementation of the image

Source: Internet
Author: User

Click to change the implementation of the image, click to change the implementation of the image

<? Xml version = "1.0" encoding = "UTF-8"?> <Selector xmlns: android = "http://schemas.android.com/apk/res/android"> <! -- The following is the android namespace --> <item android: state_focused = "true" android: state_enabled = "true" android: state_pressed = "false" android: drawable = "@ drawable/compass"/> <! -- Set the image that is not displayed when it is not pressed --> <item android: state_enabled = "true" android: state_pressed = "true" android: drawable = "@ drawable/center_bg_click"/> <! -- The image displayed when you press --> <item android: state_enabled = "true" android: state_checked = "true" android: drawable = "@ drawable/center_bg_click"/> <item android: drawable = "@ drawable/compass"/> </selector>


 

 

Usage:

1. Create a drawable folder under the res Resource Directory

2. Create an android xml file, input the above Code, and replace the corresponding image reference.

3. After the image is created, use the image as usual @ drawable/xxxx. xml (in the xml layout) or R. drawable. xxx in the program segment.

4. The reason in 3 is that after the file is created successfully. the drawable class of a java file generates a member variable referenced by the xml file name. The usage is the same as that of a common image.

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.