Created
May 7, 2018 03:36
-
-
Save MrThiago/4897424c3c773aec57081325f273311a to your computer and use it in GitHub Desktop.
How to set and reset status bar color in android
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
// 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