如何在Android上获取默认颜色

Ste*_*lis 12 android

我有一个自定义组件,我想提供与TextView相同的颜色.也就是说,我不希望复制它的颜色,我希望得到默认的前景色和背景色,如果有在Android这样的概念.

[编辑]

以下似乎产生我的TextView的文本颜色.但这只是运气吗?对我来说,默认的TextView会使用它并不直观android.R.attr.textColorSecondary吗?为什么不resolveAttribute直接返回颜色?

TypedValue tv = new TypedValue();
getContext().getTheme().resolveAttribute(android.R.attr.textColorSecondary, tv, true);
Color holyColor = getResources().getColor(tv.resourceId);
Run Code Online (Sandbox Code Playgroud)

[编辑]

我在android.git.kernel.org找到了TextView的源代码,但它似乎包含很多com.android.internal.R引用,我认为我不应该在自己的代码中使用它.我目前正在寻找一些TextView使用的证据android.R.attr.textColorSecondary.

[编辑]

我发现了某种证据developer.android.com,在styles.xmlTextView使用android.R.attr.textAppearanceSmall.textAppearanceSmall记录为默认为"辅助文本颜色".

我想我毕竟很幸运,但我仍然不喜欢我的那个小代码片段.

Dan*_*Lew 0

您正在寻找的是属性。属性将小部件链接到样式。例如,android:background是您为特定视图设置的内容,但是您可以使用诸如android:panelBackgroundandroid:windowBackground之类的属性来覆盖整个系统。

您应该查看R.attr,然后链接到小部件中的这些属性。应该有很多链接到 TextView;下载 Android 源代码并查看使用了哪些属性是有意义的。