解决了颜色,而不是资源ID而不是、解决了、颜色、资源

2023-09-07 14:05:50 作者:哥是丝袜控

最近,我已经看到出现了棉绒错误在我的code:

  

要经过这里解决了色彩,而不是资源ID:  getResources()。的getColor(R.color.maps_list_background_color)结果  MyClass.java / MyApp的/安卓/图线107的Andr​​oid皮棉问题

我知道如何解决这个问题的答案是错误的事情是我不知道为什么他们在棉短绒添加了此错误。

解决方案   称取色以整数形式

方法应传递一个RGB三元,而不是实际的颜色资源ID。必须调用getResources.getColor(资源)。

您呼叫的功能是期待一个整数,是一个RGB三联,而不仅仅是一种颜色的资源ID。颜色资源ID仍然是一个整数,但不会产生,如果它被用作RGB三,你所期望的颜色。为了传递正确的RGB三为你的颜色,你必须使用 getResources()解决它。的getColor(R.color.example_color)电话。

Recently I've seen appeared a lint error in my code:

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

网站被镜像怎么办 试试这几个方法

I know how to resolve it the answer is in the error, the thing is I don't get why they have added this error in the 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).

The function you are calling is expecting an integer that is an RGB triple, not just the id of a color resource. The color resource id is still an integer, but would not produce the color that you are expecting if it was used as the RGB triple. In order to pass it the correct RGB triple for your color, you must resolve it with the getResources().getColor(R.color.example_color) call.