Changing Color with LinearLayout and TextView in Java (Android)
- by Rob S.
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.