2011-11-18 97 views
7

Làm thế nào để thay đổi màu sắc của văn bản trong TextView trên di chuột giống như trong css với bộ chọn? Tôi biết nút để xác định bộ chọn có các mụcLàm thế nào để thay đổi màu sắc của văn bản trong TextView trên di chuột như trong css?

<item 
    android:drawable="@drawable/down" 
    android:state_pressed="true" 
    android:state_enabled="true"> 
</item> 
<item 
    android:drawable="@drawable/up" 
    android:state_focused="true" 
    android:state_enabled="true"> 
</item> 

nhưng tôi cần TextView textColor, nhưng mục không nhận ra thuộc tính đó. Có cách nào để làm điều này từ xml và không phải từ mã số ?

+0

Điều này có thể giúp bạn: http://stackoverflow.com/questions/5371719/change- clickable-textviews-color-on-focus-and-click –

Trả lời

14

Thêm selector đó như là một tập tin tài nguyên (res/color/text_color.xml)

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_focused="true" android:color="@color/focused_text_color"/> 
    <item android:state_pressed="true" android:state_enabled="false" android:color="@color/pressed_text_color" /> 
    <item android:state_enabled="false" android:color="@color/disabled_text_color" /> 
    <item android:color="@color/default_text_color"/> 
</selector> 

Và sử dụng nó:

android:textColor="@color/text_color" 
Các vấn đề liên quan