Android TextView selector click Style change)

Source: Internet
Author: User

1.selector from the meaning of the word: The selector is the control of your goal. Selector is primarily used in the ListView item click Style and TextView and button's click Style.

2. The main attributes are:

Android:state_selected selected

Android:state_focused Get Focus

android:state_pressed Click

Android:state_enabled setting whether to respond to an event, refers to all events

3. Here's an example of selector setting for TextView:

1). Create a drawable folder under Res to install textselector.xml, place the definition of the click Style

2). Load the Textselector.xml resource on the TextView

Textselector.xml

<?XML version= "1.0" encoding= "Utf-8"?><selectorxmlns:android= "Http://schemas.android.com/apk/res/android">    <ItemAndroid:color= "#45c01a"android:state_pressed= "true"/>    <ItemAndroid:color= "#9a9a9a"/></selector>

Activity_main.xml

<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent" >    <TextViewAndroid:id= "@+id/textview"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_centerhorizontal= "true"Android:paddingbottom= "4DP"Android:text= "Home"Android:textcolor= "@drawable/textselector"android:textsize= "20SP" >    </TextView></LinearLayout>

However, after running the program click TextView will not see TextView color changes, this is because the TextView has not been added to listen to the event, even if the event does not take what function must be set.

     TextView TextView = (TextView) Findviewbyid (R.id.textview);     Textview.setonclicklistener (null);

Android TextView selector click Style change)

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.