This article describes the method of adding selectors to controls in Android development implementation layout. Share it for your reference, as follows:
During the development process, some display effects of dynamic interaction can be achieved by adding selectors to the layout, which can reduce the number of codes such as Activity and reduce coupling in MVP development, so that developers only need to pay attention to logical processing when writing code.
For example: a button, the original background image is red, the font is black, the background image is yellow when clicked, and the font is changed to white.
This kind of simple effect can be achieved when laying out:
<Button android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Experience now" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="80dp" android:textSize="25sp" android:textColor="@drawable/guide_btntext_selector" android:background="@drawable/guide_btn_selector" android:paddingTop="5dp" android:paddingBottom="5dp" android:paddingRight="20dp" android:paddingLeft="20dp" android:visibility="gone" />
@drawable/guide_btntext_selector
for
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:andro > <item android:state_pressed="true" android:color="#000"/> <item android:state_pressed="false" android:color="#fff"/> </selector>
@drawable/guide_btn_selector
for
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:andro > <item android:state_pressed="true" android:drawable="@drawable/button_red_pressed"/> <item android:state_pressed="false" android:drawable="@drawable/button_red_normal"/> </selector>
For more information about Android related content, please check out the topic of this site:Summary of Android window related operation skills》、《Android development introduction and advanced tutorial》、《Android debugging skills and solutions to common problems》、《Summary of the usage of basic Android components》、《Android View View Tips Summary》、《Android layout layout tips summary"and"Android control usage summary》
I hope this article will be helpful to everyone's Android programming design.