1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > Android代码中更改TextView颜色

Android代码中更改TextView颜色

时间:2022-09-04 13:34:29

相关推荐

Android代码中更改TextView颜色

项目中,需要在代码中动态更改TextView的颜色,原先使用如下:

text.setTextColor(R.color.black);

为生效,查阅资料后,正确写法如下:

text.setTextColor(context.getResources().getColor(R.color.black));

或:

text.setTextColor(getResources().getColorStateList(R.color.black));

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。