Click the text color to achieve TextView switch

How to achieve TextView Click the text color switch

  • 1. Create a new file in res color directory folder, the new color_resource_file file in that folder

  • 2. Set the color before and after clicking in the new color resource file separately

/**
 * color_xml_selector_text.xml
 */
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@color/lv_54ba3d" android:state_pressed="true"/>
    <item android:color="#de000000"/>
</selector>
  • 3. In the property by TextView android: Set Text Color textColor
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ...
    android:textColor="@color/color_xml_selector_text"/>

Guess you like

Origin www.cnblogs.com/Ricardoldc/p/12661465.html