gpt4 book ai didi

android - Resources$NotFoundException 将属性作为颜色访问时

转载 作者:太空狗 更新时间:2023-10-29 13:46:41 24 4
gpt4 key购买 nike

所以我将颜色定义为属性,因为它取决于主题。

<attr name="primary_text_color" format="color"/>

在主题中定义为

<style name="BaseReferencesTheme" parent="Theme.AppCompat.NoActionBar">
<item name="primary_text_color">#ffffffff</item>
</style>

我想用真实的颜色资源包装它。

<color name="selected_color_normal">?attr/primary_text_color</color>

然后从代码中读取它

int resolvedColor = ContextCompat.getColor(context, R.color.selected_color_normal);

当我这样做时,出现异常

 android.content.res.Resources$NotFoundException: Resource ID #0x7f06010e type #0x2 is not valid
at android.content.res.Resources.getColor(Resources.java:955)
at android.content.Context.getColor(Context.java:588)
at android.support.v4.content.ContextCompat.getColor(ContextCompat.java:523)

我在这里使用了几个模块:

  1. attr_module 定义属性的位置。
  2. theme_module 定义主题并将其设置为应用程序
  3. usage_module 对主题一无所知,但确实依赖于 attr_module

我确定该主题已应用于 usage_module 中的 View 。当我不尝试以编程方式读取 selected_color_normal 时,所有依赖项都已正确设置,而只是应用属性 - 一切正常。

感谢您的帮助!

最佳答案

目前我认为这个问题无法解决。目前我的方法是尽可能使用 ?attr/primary_text_colorR.attr.primary_text_color

关于android - Resources$NotFoundException 将属性作为颜色访问时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52608118/

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