Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setBackgroundDrawable not working properly [duplicate]

In my application, I am using actionbarsherlock. I use

getSupportActionBar().setBackgroundDrwable(R.drawable.test).

It works fine, the color is showed as expected, however when I go to another activity and go back to the main activity. The bar color is changed to black (in my program, I dont set black for the backgrounddrawble and just call setSupportAction().setBackgroundDrawable in onStart()). However, if I change the code to

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(0xff550000)));

The app works fine. When I click on back button, the color is set to 0xff55000 which is expected.

like image 791
Sam nguyen Avatar asked Sep 13 '26 07:09

Sam nguyen


1 Answers

I will suggest not to use the color code directly this way while you are trying to set the color programmatically. It will not take it. just try out this way..

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(mContext.getResources().getColor(Color.BLACK)));

Hope it will work for you.

like image 187
Swati Avatar answered Sep 14 '26 21:09

Swati



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!