Skip to content

Instantly share code, notes, and snippets.

@dynoChris
Created December 9, 2018 01:03
Show Gist options
  • Save dynoChris/28be9fb2a1fad91cfb1247509b60feef to your computer and use it in GitHub Desktop.
Save dynoChris/28be9fb2a1fad91cfb1247509b60feef to your computer and use it in GitHub Desktop.
How to make transparent status bar in Android
public class StatusBarUtils {
public static void makeTransparentStatusBar(Activity activity) {
if (Build.VERSION.SDK_INT >= 19 && Build.VERSION.SDK_INT < 21) {
setWindowFlag(activity, true);
}
if (Build.VERSION.SDK_INT >= 19) {
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
//make fully Android Transparent Status bar
if (Build.VERSION.SDK_INT >= 21) {
setWindowFlag(activity, false);
activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
}
}
private static void setWindowFlag(Activity activity, boolean on) {
Window win = activity.getWindow();
WindowManager.LayoutParams winParams = win.getAttributes();
if (on) {
winParams.flags |= WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
} else {
winParams.flags &= ~WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
}
win.setAttributes(winParams);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment