Change color when Android text is clicked

Source: Internet
Author: User

1. In Colors.xml, add two item. Note that the label for these two item is <drawable>, not <color>!

<name="Primary_green" > #8cb800 </drawable>
<name="Gray" > #C2C2C2 </

2. Add Txt_color_green_gray.xml in drawable. android:color < Span style= "color: #ff0000;" > instead of android:d rawable.

<?XML version="1.0"encoding="Utf-8"?>
<SelectorxmlnsAndroid="Http://schemas.android.com/apk/res/android" >
<ItemAndroid: color="@drawable/gray"
android: state_pressed="true"/>
<item Android: color="@drawable/primary_green"
android: state_pressed="false"/>
</selector>

3. Use the Txt_color_green_gray.xml created above in TextView:

<TextView
Android: layout_width="Match_parent"
Android: layout_height="Wrap_content"
Android: clickable="True"
android: Gravity= android:text= android:textcolor= "@drawable/txt_color_green_gray"
android: Textsize=

Color change when you click on Android text

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.