Skip to content

Instantly share code, notes, and snippets.

@MrThiago
Created May 7, 2018 03:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrThiago/4897424c3c773aec57081325f273311a to your computer and use it in GitHub Desktop.
Save MrThiago/4897424c3c773aec57081325f273311a to your computer and use it in GitHub Desktop.
How to set and reset status bar color in android
// Change the status bar color => REQUIRES API 21 and above
private static int defaultStatusBarColor;
public static void changeStatusBarColor(Activity context, boolean change, int color){
if (Build.VERSION.SDK_INT >= 21)
{
Window window = context.getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
if(change){
defaultStatusBarColor = window.getStatusBarColor();
window.setStatusBarColor(color);
}
else{
// reset
window.setStatusBarColor(defaultStatusBarColor);
}
}
}
// to Set
changeStatusBarColor(getActivity(), true, color);
// to Reset
changeStatusBarColor(getActivity(), false, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment