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
view.setBackgroundColor(R.color.blue)
but this does not works because it doesn't matter what color I set for backgro开发者_运维技巧und, 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.
Try:
view.setBackgroundColor(getResources().getColor(R.color.blue));
use
view.setBackground(getResources().getDrawable(R.color.Gray));
精彩评论