设置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