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