Use of Android Selector

Source: Internet
Author: User

First still have to spit groove, a few days ago want to write blog, but always is not on the landing. Other Web site technical blog, such as CSDN is also unable to view, a lot of questions Baidu to the answer to see the blog.csdn words are not expected to open. A technical blog has been reduced to the point of no open, no matter for what reason believe it will be a thing that people can not imagine.

Okay, here we are. Recently in the UI of the application, mainly the effect of button. Previously, Ontouchlistener was used to monitor the touch events of the button, although ultimately it was possible to achieve the desired effect, but the huge amount of code is a violation of the spirit of programming and principles of behavior. All the control effects are then rewritten with selector.

Have to say, selector is easy to use and fast, although compared to iOS UIButton, but also a little bit, but compared to the original method is also a great improvement. The main idea of selector is to differentiate different states and set drawable in different states. There are two issues to note:

1, order problems. A selector can have more than one item, but the default state of item must be written on the last, otherwise it will not achieve the desired effect (this pit wasted a lot of my time.) )

2, use color. The item default property does not have android:color this option, so to use colors in RGB format to write color resources to strings, and then reference @color/xxx in the Drawable property to implement the use of colors.

In addition to buttons, other controls, such as EditText, can be used to write selector to implement UI transformations in different states.

Use of Android Selector

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.