Android selector usage instructions

Source: Internet
Author: User

Android selector usage instructions

1. Create an xml file at drawable/xxx. xml. Remember to put the relevant images in the same directory.







Android: drawable = "@ drawable/pic1"/>

Android: state_pressed = "true" Android: drawable = "@ drawable/pic2"/>

Android: state_pressed = "true" Android: drawable = "@ drawable/pic3"/>

Android: drawable = "@ drawable/pic4"/>

Android: drawable = "@ drawable/pic5"/>

Ii. Use an xml file:

1. Method 1: Configure android: listSelector = "@ drawable/xxx in listview
Alternatively, you can add the property android: background = "@ drawable/xxx" to the listview item"

2. Method 2: Drawable drawable = getResources (). getDrawable (R. drawable. xxx );
ListView. setSelector (drawable); however, when the list is sometimes black, you must add android: cacheColorHint = "@ android: color/transparent" to make it transparent.

Related attributes:

Android: state_selected is selected
Android: state_focused is the focal point
Android: state_pressed: Click
Android: state_enabled is used to set whether to respond to events. It refers to all events.

You can also set the selector effect of the button Based on these statuses. You can also set selector to change the text status in the button.


Configure the text effect in the button:
Drawable/button_font.xml







Button can also achieve more complex effects, such as gradient
Drawable/button_color.xml

/
// Define the form when the button is in the pressed state.

Android: startColor = "# 8600ff"/>

Android: width = "2dp" android: color = "#000000"/>


Android: bottom = "10dp" android: right = "10dp"/>

// Define the form when the button obtains the focus


Color = "# ffffff"/>


Android: bottom = "10dp" android: right = "10dp"/>



Finally, you need to add two items to the xml file containing the button. For example, in the main. xml file Add two android: focusable = "true"Android: background = "@ drawable/button_color"

Related Article

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.