简体   繁体   中英

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 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));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM