这两天优化项目中,踩了个坑,记录一下,防止下次碰上了,解决不了
这个坑太小了
protected void setTitleTextColor(int color) {
String currentColor = "#" + Integer.toHexString(color).substring(2);
MLog.d("ssss", " CurrentText color : " + color + " " + currentColor);
super.setTitleTextColor(color);
TextView textView = findViewById(R.id.txt_top_center);
if (textView != null) {
String hexColor = "#" + Integer.toHexString(textView.getCurrentTextColor()).substring(2);
MLog.d("ssss", " textView color : #" + textView.getCurrentTextColor() + " " + hexColor);
}
}
Integer.toHexString(textView.getCurrentTextColor()).substring(2);
是把int 值转换成RGB值
坑就是:
setTitleTextColor(getResources().getColor(R.color.white));是白色
setTitleTextColor(R.color.white);显示出来的不是白色 是别的颜色,
用getResources().getColor(R.color.white) 就对了