【发布时间】:2018-04-21 15:37:53
【问题描述】:
在 Android 中,我尝试从 res/values/colors.xml 设置颜色
使用title.setBackgroundColor()
目前我可以设置为:title.setBackgroundColor(Color.GREEN);
但是,我想引用 .xml 中的颜色
当我使用时:
title.setBackgroundColor(R.color.white);
指:
<color name="white">#FFFFFF</color>
Andriod 工作室报告:
Should pass resolved color instead of resource id here: `getResources().getColor(R.color.white)` less... (⌘F1)
This inspection looks at Android API calls that have been annotated with various support annotations (such as RequiresPermission or UiThread) and flags any calls that are not using the API correctly as specified by the annotations. Examples of errors flagged by this inspection:
Passing the wrong type of resource integer (such as R.string) to an API that expects a different type (such as R.dimen).
Forgetting to invoke the overridden method (via super) in methods that require it
Calling a method that requires a permission without having declared that permission in the manifest
Passing a resource color reference to a method which expects an RGB integer value.
...and many more. For more information, see the documentation at http://developer.android.com/tools/debugging/annotations.html
【问题讨论】:
-
尝试设置
title.setBackgroundColor(ContextCompat.getColor(context, R.color.white));
标签: android android-layout android-color