Should pass resolved color instead of resource id here: getResources().getColor(R.color.brown)

简介: Should pass resolved color instead of resource id here: getResources().getColor(R.color.brown)

Should pass resolved color instead of resource id here: getResources().getColor(R.color.brown)


调用TextView的 setBackgroundColor方法 传入的是color 的id 导致设置颜色背景无效,Android studio 提示

Should pass resolved color instead of resource id here: getResources().getColor(R.color.brown)
valueView.setBackgroundColor(R.color.brown);


原因:就是R.color.xxx只是一个给定的整数id,不是方法要求的三原色的整数,所以要调用 getResources().getColor(R.color.xxx)来转化


解决方法 :调用 getResources().getColor转换

valueView.setBackgroundColor(mContext.getResources().getColor(R.color.greenyellow));
目录
相关文章
Failed to execute ‘setAttribute‘ on ‘Element‘: ‘;min-height:‘ is not a valid attribute name.添加100vh
Failed to execute ‘setAttribute‘ on ‘Element‘: ‘;min-height:‘ is not a valid attribute name.添加100vh
|
3月前
|
开发工具 git
Stylelint—— Expected class selector ".nut-popup--top" to be kebab-case selector-class-pattern
新项目制定规范接入了stylelint,并通过husky在git提交时去触发检测修复,因为使用的是NutUi,所以无法直接调整组件对应的类名称,只好在stylelint.config.js中加入相应的rules进行配置。
78 0
|
3月前
|
CDN
Iconfont——Error: <path> attribute d: Expected number, "MNaNNaNaNaNNaNNaN…".
Iconfont——Error: <path> attribute d: Expected number, "MNaNNaNaNaNNaNNaN…".
34 0
Unknown custom element: <add-employee> - did you register the component correctly? For red cursive c
原因: 1.组件名没写对(导入和注册不对应) 2.components少写了个s 3.组件命名最好是驼峰命名 4.导入时语法错误 5.代码中有两个components,后一个的值把前一个覆盖了 6.组件直接循环套用了
background引起错误:Error inflating class
background引起错误:Error inflating class
167 0
PAT (Advanced Level) Practice - 1135 Is It A Red-Black Tree(30 分)
PAT (Advanced Level) Practice - 1135 Is It A Red-Black Tree(30 分)
98 0
how is opportunity detail page display first item by default
how is opportunity detail page display first item by default
91 0
how is opportunity detail page display first item by default
CPS fact debug - Continuation-pass style
Created by Wang, Jerry, last modified on Dec 24, 2015
178 0
CPS fact debug - Continuation-pass style
另一种Background job的 debug方法
另一种Background job的 debug方法
104 0