You should use a selector resource for this purpose.
Custom style on TextView widget
-
30-06-2023 - |
سؤال
I want to create a custom textview style where the text color changes on focus or on being selected and when released or not focused it changes back to the default color I have set. Below is my custom style I declared and applied to the style
element of my textview
<style name="CustomTextview" parent="android:style/Widget.Holo.TextView">
<item name="android:state_pressed">@android:color/holo_red_dark</item>
<item name="android:state_selected">@android:color/holo_red_dark</item>
<item name="android:state_focused">@android:color/holo_red_dark</item>
</style>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Yes"
android:id="@+id/textView2"
android:layout_weight="1"
android:gravity="center"
android:textStyle="bold"
android:editable="false"
android:singleLine="true"
android:clickable="true"
android:padding="10dp"
style="@style/CustomTextview"
android:focusable="true"/>
Currently nothing happens when I toch the textview, the default color is black and when I press the textview the color remains black.
المحلول
نصائح أخرى
You should follow this tutorial http://developer.android.com/guide/topics/resources/color-list-resource.html
Then you need to sect text color of TextView with color that you have define
لا تنتمي إلى StackOverflow