Change actionbar color programmatically more than once
Try this,
Method1:
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(0xff00FFED));
Method2:
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources()
.getColor(R.color.bg_color)));
Method3:
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#3A1212")));
Kotlin
supportActionBar?.setBackgroundDrawable(ColorDrawable(ContextCompat.getColor(this, android.R.color.black)))
getColor is deprecated. use ContextCompat :
bar.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(context, R.color.app_bar_online)));
I had the same problem, answer from user1634451 worked but only once (would not enable several color switches in a row)
This definitely fixed it:
bar.setBackgroundDrawable(new ColorDrawable(getResources()
.getColor(R.color.app_bar_online)));
Instead of directly linking to the color doing new ColorDrawable(R.color.app_bar_online)
this is a quick fix that i found
mActionBar.setBackgroundDrawable(new ColorDrawable(0xff00DDED));
mActionBar.setDisplayShowTitleEnabled(false);
mActionBar.setDisplayShowTitleEnabled(true);