How Do I set the background color of my android app. When I try:
LinearLayout li=(LinearLayout)findViewById(R.id.myLayout);
li.setBackgroundColor(Color.parseColor("#rrggbb"));
My app always crashes. Could someone help me out. Thanks
How Do I set the background color of my android app. When I try:
LinearLayout li=(LinearLayout)findViewById(R.id.myLayout);
li.setBackgroundColor(Color.parseColor("#rrggbb"));
My app always crashes. Could someone help me out. Thanks
This question is a old one but it can help for others too.
Try this :
By the way, a good tip on quickly selecting color on the newer versions of AS is simply to type #fff and then using the color picker on the side of the code to choose the one you want. Quick and easier than remembering all the color hexadecimals. For example:
Try this:
EDIT: Posting logcat file would also help.
instead of
#rrggbb
you should be using hex values 0 to F for rr, gg and bb:e.g.
Color.parseColor("#000000")
orColor.parseColor("#FFFFFF")
Source
From documentation:
So I believe that if you are using
#rrggbb
you are getting IllegalArgumentException in your logcatSource
Alternative:
Source