解决了颜色,而不是资源ID [英] Resolved color instead of a resource id

查看:1895
本文介绍了解决了颜色,而不是资源ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我已经看到出现了棉绒错误在我的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.

这篇关于解决了颜色,而不是资源ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆