我在xml中定义了一个TextView。该 textColor
在Android Studio属性面板中的属性显示为 [default] "@android:color/secondary_text_material_light"
.
如何在需要的时候,通过程序获取这个默认颜色来重置TextView的颜色?
PS: 我已经阅读了 此职位 但它似乎没有回答我的问题。
你可以用这行代码来获得一个定义为颜色资源的颜色。
ContextCompat.getColor(context, android.R.color.secondary_text_material_light);
我还没有测试过,但我觉得应该可以用,希望能帮到你。
EDIT 1:如果问题出在文字颜色的设置上...
你可以通过 textView.setTextColor()
方法,完整的代码可能是这样的。
your_text_view.setTextColor(ContextCompat.getColor(this, android.R.color.secondary_text_material_light));
我最后采用了以下的变通方法。
textView.setTextColor(TextView(context).textColors)