我试图在运行时重置TextView的TextColor。我想获取TextView的默认颜色作为@ColorInt
。我相信当前的主题知道这个。
下面是我尝试过的:
public @ColorInt int getDefaultThemeColor(int attribute) {
TypedArray themeArray = mContext.getTheme().obtainStyledAttributes(new int[] {attribute});
try {
int index = 0;
int defaultColourValue = 0;
return themeArray.getColor(index, defaultColourValue);
}
finally {
themeArray.recycle();
}
}
其中属性是:
android.R.attr.textColor
android.R.attr.textColorPrimary
android.R.attr.textColorSecondary
但它们都不能正确检索颜色。我还尝试替换该方法的第一行:
TypedArray themeArray = mContext.getTheme().obtainStyledAttributes(R.style.AppTheme, new int[] {attribute});
我不想采用以下的不太优雅的解决方案:
- 获取并存储TextView的textColor
- 将颜色更改为任何颜色
- 将其重置回以前存储的值
有什么提示吗?
TextView
的默认颜色为#666666
。 - V-rund Puro-hit