【发布时间】:2016-01-08 03:41:43
【问题描述】:
如何以编程方式将TextView 的文本颜色设置为?android:textColorPrimary?
我已经尝试了下面的代码,但是它将 textColorPrimary 和 textColorPrimaryInverse 的文本颜色始终设置为白色(它们都不是白色,我已经通过 XML 进行了检查)。
TypedValue typedValue = new TypedValue();
Resources.Theme theme = getActivity().getTheme();
theme.resolveAttribute(android.R.attr.textColorPrimaryInverse, typedValue, true);
int primaryColor = typedValue.data;
mTextView.setTextColor(primaryColor);
【问题讨论】:
-
通常我扩展 TextView 类并在应用程序的任何地方使用它。在我的 TextView 类中,我设置了默认颜色、字体等。另一种方法是制作具有所需颜色的静态变量并使用 .setTextColor();到处。第三种方法是使用新的 Android Studio (1.4) 主题调试器来编辑您的主题。我知道这不是直接的答案,但它可能是一个很好的解决方法。
-
我不打算在任何地方使用
setTextColor。我想为特定的TextView设置从次要到主要的颜色。 -
你能不能把它当作... ..
mTextView.setTextColor(android.R.attr.textColorPrimary); -
@sourabhbans 不,这不起作用:(
-
您是否在为应用使用自定义主题?
标签: android textview android-theme