安卓编程 设置组件字体颜色

 

 

 

学习《疯狂android》其中涉及到给组件设置字体颜色的代码。下面的集中方法和报错。最后在一个英文网站上找到了最后一种方法,不会提是错误

 

/*

第一种:Should pass resolved color instead of resource id here: getResources().getColor(R.color.red)

*/

//text.setTextColor(R.color.red);

/*

The method getColor(int) from the type Resources is deprecated

*/

//text.setTextColor(getResources().getColor(R.color.red));

/*

在网上查询都说这个方法是替换已经过时的方法:getResources().getColor(R.color.red)的。但是不好使,也无法在API上查询到ContextCompat下有getColor()方法。也可能是我不会用

The method getColor(TextView, int) is undefined for the type ContextCompat

*/

//ContextCompat.getColor(text,R.color.red);

/*

这个用法同样会提是上面的错误

*/

//text.setTextColor(ContextCompat.getColor(text, R.color.red));

/*

  在一个英文网站上查询到,有个人说他用下面这个方法设置字体颜色。我使用后至少还没有报错,不知道是否有效果

*/

text.setTextColor(Color.RED);

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值