我有一个自定义组件,我想提供与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.xml该TextView使用android.R.attr.textAppearanceSmall.textAppearanceSmall记录为默认为"辅助文本颜色".
我想我毕竟很幸运,但我仍然不喜欢我的那个小代码片段.
| 归档时间: |
|
| 查看次数: |
11666 次 |
| 最近记录: |