設置TextView按下時變換文字顏色


 
在res中建立一個color文件夾,在其中新建一個xml(這里為text_color.xml):
 
1
2
3
4
< selector xmlns:android = "http://schemas.android.com/apk/res/android" >
< item android:state_pressed = "true" android:color = "@color/white" ></ item >
< item android:color = "@color/login_footerbutton_n" ></ item >
</ selector >
 
然后設置你的TextView屬性:
 
1
2
3
4
5
6
7
8
< TextView
android:id = "@+id/textView3"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:textColor = "@color/text_color"
android:textSize = "11dp"
android:clickable = "true"
android:text = "忘記密碼" />
 
重點要講一下的是 clickable屬性,默認該屬性為false,此時TextView是不可點擊的,也就不會有變換顏色的效果。所以要將該屬性設為true。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM