Bitte versuchen Sie den folgenden Code und führen Sie mich, mein Problem ist, dass Ich bekomme nicht den "gepressten" Zustand für die TextView, ist es möglich zu implementieren Gepresster Zustand für das TextView? wie mache ich?Android - Problem which TextView Hintergrundfarbe ändern auf dem anderen Zustand davon
Ich habe einen Erfolg mit dem folgenden Code für die Schaltfläche, aber nicht erfolgreich für die TextView.
pls mich leiten
My Button und Textview-Code:
<Button
android:id="@+id/Button01"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="@drawable/button_state"
android:padding="20dp">
</Button>
<TextView
android:text="Demo of Color on state change"
android:id="@+id/TextView01"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="@drawable/button_state"
android:focusable="true">
</TextView>
button_state.xml
Datei (ich es in ziehbar Ordner gespeichert haben):
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<gradient
android:startColor="@color/yellow1"
android:endColor="@color/yellow2"
android:angle="270" />
<stroke
android:width="3dp"
android:color="@color/grey" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item android:state_focused="true" >
<shape>
<gradient
android:endColor="@color/orange1"
android:startColor="@color/orange2"
android:angle="270" />
<stroke
android:width="3dp"
android:color="@color/grey" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:endColor="@color/blue1"
android:startColor="@color/blue2"
android:angle="270" />
<stroke
android:width="3dp"
android:color="@color/grey" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
</selector>
color.xml
Datei:
<resources>
<color name="yellow1">#FFFF99</color>
<color name="yellow2">#FFCC00</color>
<color name="orange1">#FF9966</color>
<color name="orange2">#FF6600</color>
<color name="blue1">#99CCFF</color>
<color name="blue2">#0033CC</color>
<color name="grey">#736F6E</color>
</resources>
Ich habe die Frage zu SO mit dem gleichen Thema, aber ohne eine sinnvolle Antwort: http://stackoverflow.com/questions/4336218/android-textview-change-color-on-changing-of-state –