سؤال

I already read a lot of questions like these, and tried all the suggestions, but still when I click above the textview the color doesn't change.

Also tried using the method onClick, cast the view to TextView and calling the method setTextColor, and also didn't work.

This was my last attempt:

XML Layout File:

<LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/promptDefine"
        android:orientation="vertical"
        android:gravity="center"
         >

            <TextView
                android:textSize="20sp"
                android:onClick="addItem"
                android:clickable="true"
                android:textColor="@color/selector_txt"
                android:layout_marginTop="10dip"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:hint="@string/addItem" />
        </LinearLayout>

This is my selector_txt XML file at color folder:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="true" android:color="#00ff00"/>
    <item android:state_pressed="true" android:state_enabled="false" android:color="#ff0000" />
    <item android:state_enabled="false" android:color="#0000ff" />
    <item android:color="#00f0f0"/>
</selector>

Where is the problem?

هل كانت مفيدة؟

المحلول

LOL What a joke, its not possible because I didnt had text.. only hint text and textColor only works for text .

Solution:

<LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/promptDefine"
        android:clickable="true"
        android:orientation="vertical"
        android:gravity="center"
         >

            <TextView
                android:textSize="20sp"
                android:text="testing..."
                android:clickable="true"
                android:textColor="@color/selector_txt"
                android:layout_marginTop="10dip"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:hint="@string/addItem" />

</LinearLayout>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top