TextView.setTextColor(int value),括号里是int型的值,可以填充的值有三种情况。

第一种:系统自带的颜色类,TextView.setTextColor(android.graphics.Color.RED)

第二种:十六进制的颜色值,TextView.setTextColor(0xffff3030);

说明:0x是代表颜色整数的标记,ff是表示透明度,ff3030表示颜色。必须是8位的颜色表示,6位的ff3030是错误的

第三种:通过获得资源文件进行设置,TextView.setTextColor(this.getResources().getColor(R.color.red));

说明:根据不同的情况getColor()可以是R.color.red、R.string.red和R.drawable.red,但必须提前在相应的配置文件里做相应的配置。如:

<color name="red">#ff3030</color>
<drawable name="red">#ff3030</drawable>
<string name="red">#ff3030</string>

相关文章:

  • 2022-12-23
  • 2021-11-03
  • 2022-02-05
  • 2022-03-04
  • 2021-04-28
  • 2021-12-27
  • 2022-01-22
  • 2021-08-29
猜你喜欢
  • 2022-12-23
  • 2021-07-19
  • 2021-04-25
  • 2021-12-23
  • 2022-02-05
  • 2021-12-28
相关资源
相似解决方案