gpt4 book ai didi

android - 解析颜色而不是资源 ID

转载 作者:IT王子 更新时间:2023-10-29 00:01:04 29 4
gpt4 key购买 nike

最近我看到我的代码中出现了一个 lint 错误:

Should pass resolved color instead of resource id here: getResources().getColor(R.color.maps_list_background_color)
MyClass.java /myapp/android/maps line 107 Android Lint Problem

我知道如何解决它,答案在错误中,问题是我不明白为什么他们在 linter 中添加了这个错误。

最佳答案

Methods that take a color in the form of an integer should be passed an RGB triple, not the actual color resource id. You must call getResources.getColor(resource).

您正在调用的函数需要一个 RGB 三元组的整数,而不仅仅是颜色资源的 id。颜色资源 id 仍然是一个整数,但如果将其用作 RGB 三元组,则不会产生您期望的颜色。为了将正确的 RGB 三元组传递给您的颜色,您必须使用 getResources().getColor(R.color.example_color) 调用来解决它。

关于android - 解析颜色而不是资源 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13989319/

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