Changing Color with LinearLayout and TextView in Java (Android)

Posted by Rob S. on Stack Overflow See other posts from Stack Overflow or by Rob S.
Published on 2011-01-17T16:45:22Z Indexed on 2011/01/17 16:53 UTC
Read the original article Hit count: 205

I'm a relatively new Android developer and I noticed what seems like an oddity to me that I'm hoping someone can explain. I have LinearLayout ll.

This line of code fails for me when executed:

ll.setBackgroundColor(R.color.white);

However this line of code works:

ll.setBackgroundResource(R.color.white);

I assume its simply because I have white defined in my resources. However, I've also tried passing 0xFFFFFF in setBackgroundColor() and that doesn't work either.

Similarly with my TextView text this line of code fails when executed:

text.setTextColor(R.color.white);

I can see my TextView so I know I initialized it correctly (like my LinearLayout which I can also see). So I guess my question boils down to: How do I properly use LinearLayout.setBackgroundColor() and TextView.setTextColor() ?

Thanks a ton in advance. I've read through the docs and tried to find information online via googling and haven't come up with anything.

© Stack Overflow or respective owner

Related posts about java

Related posts about android