//第1种:
txt.setTextColor(android.graphics.Color.RED); // 系统自带的颜色类
//第2种:
txt.setTextColor(android.graphics.Color.parseColor("#87CEFA")); // 使用Color类转换
//第3种:
txt.setTextColor(0xffff00ff); // 0xffff00ff是int类型的数据,分组一下0x|ff|ff00ff,0x是代表颜色十六进制整数的标记,ff是表示透明度,ff00ff表示颜色。注意:这里ffff00ff必须是8位颜色格式,不接受ff00ff这种6位的颜色格式。
//第4种:
txt.setTextColor(this.getResources().getColor(R.color.red));
原文链接:https://blog.csdn.net/chenzhengfeng/article/details/81067186