Android按钮设置文字变色
16lz
2021-01-24
currentButton.setTextColor(R.color.white); 这种直接值颜色的ID进去,发现文字都变成黑色的了,所以需要使用setTextColor(ColorStateList colors) 这个方法,传入ColorStateList对象 ColorStateList whiteColor=getResources().getColorStateList(R.color.white); currentButton.setTextColor(whiteColor); 这样文字就可以变颜色了 ColorStateList 对象可以在 XML 中定义,像 color 一样使用,它能根据它应用到的 View 对象的状态实时改变颜色。例如, Button 可以存在多种状态( pressed 、 focused 或 other ),如果使用 ColorStateList ,你就能为它的每个状态提供不同的颜色。
更多相关文章
- Android屏幕手写签名的实现-详细篇
- Android(安卓)-- 检测耳机插入状态
- android animator
- Android(安卓)MediaPlayer类
- Android(安卓)Vold 分析(一)--system/vold/main.cpp-----mian函数
- android TextView实现多种颜色显示
- Android常用系统广播
- Android调用ITelephony类的endCall()方法 实现来电拒接
- 关于Activity的生命周期的一些见解