Created
December 9, 2018 01:03
-
-
Save dynoChris/28be9fb2a1fad91cfb1247509b60feef to your computer and use it in GitHub Desktop.
How to make transparent status bar in Android
This file contains 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
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