Last active
August 29, 2015 14:06
-
-
Save CarlosMChica/9076175fae4f01b1dab5 to your computer and use it in GitHub Desktop.
Workaround to change action bar background dynamically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Looks like drawable is still not ready to be set when applying it to the action bar | |
//in versions bellow 17 with default method. The action bar needs to be redrawed and it can be forced by using | |
//the following workarround | |
public void setActionBarbackground(ColorDrawable colorDrawable) { | |
ActionBar actionBar = getActionBar(); | |
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { | |
actionBar.setBackgroundDrawable(colorDrawable); | |
//switch true/false values if title is not needed | |
actionBar.setDisplayShowTitleEnabled(false); | |
actionBar.setDisplayShowTitleEnabled(true); | |
} else { | |
getActionBar().setBackgroundDrawable(colorDrawable); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You won't need to call
getActionBar()
again inelse
condition, just use your variable.