如何获取android TextView的默认文本颜色?

新手上路,请多包涵

我无法在 Android 23 中获得 TextView(可能还有其他视图)的默认灰色文本颜色。

我试图用这段代码得到它:

 TextView textview= (TextView) mActivity.findViewById(R.id.my_textview);

int colorFirstTry = title.getCurrentTextColor(); // black
int colorSecondTry = title.getTextColors().getDefaultColor(); // black
int colorthirdTry = ContextCompat.getColor(mActivity, android.R.color.primary_text_light); // black

我的主题是空白活动项目中使用的默认主题(来自 Theme.AppCompat.Light.DarkActionBar 父级的 AppTheme)。 colorPrimary、colorPrimaryDark 和 colorAccent 的颜色分别为蓝色、深蓝色和紫色。

当我浏览所有 Theme.AppCompat.Light.DarkActionBar 父母时,我发现了一个类似的灰度值:

 <style name="Base.V7.Theme.AppCompat.Light" parent="Platform.AppCompat.Light">
    ...
    <item name="colorPrimaryDark">@color/primary_dark_material_light</item>

但是这个值应该被我的应用程序主题值覆盖。

原文由 Burrich 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 643
1 个回答

正如 Alex 所说,您可以通过 以下 方式获得它:

 android:textColor="@android:color/tab_indicator_text"

要么

#808080

它对我很有用!

原文由 Alysson Myller 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题