gpt4 book ai didi

android - 如何在 Android 上获取默认颜色

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:48:43 25 4
gpt4 key购买 nike

我有一个自定义组件,我想提供与 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);

[编辑]

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

[编辑]

我在 developer.android.com 找到了一些证据, 在 styles.xml TextView 使用 android.R.attr.textAppearanceSmalltextAppearanceSmall 被记录为默认为“辅助文本颜色”。

我想我毕竟是幸运的,但我仍然不喜欢我的那个小代码 fragment 。

最佳答案

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

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

关于android - 如何在 Android 上获取默认颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3161462/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com