[英]android set list item custom background color
I need to set a custom color to a list item based on a property of item from adapter and I can not use a selector (condition for item to have custom color is an item property, not a selected or focused state). 我需要根据适配器中项目的属性为列表项设置自定义颜色,我不能使用选择器(项目的条件是自定义颜色是项目属性,而不是选定或聚焦状态)。 In getView method I set 在我设置的getView方法中
view.setBackgroundColor(R.color.blue)
but this does not works because it doesn't matter what color I set for background, the result is the same. 但这不起作用,因为我为背景设置的颜色无关紧要,结果是一样的。 I tried to set background color to the layout but the result is the same. 我尝试将背景颜色设置为布局,但结果是一样的。 Can you please give me a clue? 你能告诉我一个线索吗? Thanks 谢谢
use , 采用 ,
view.setBackgroundResource(R.color.blue)
it will work. 它会工作。
采用
view.setBackground(getResources().getDrawable(R.color.Gray));
尝试:
view.setBackgroundColor(getResources().getColor(R.color.blue));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.