Created
May 12, 2020 08:29
-
-
Save socmia/a8a7fc81da994783259611575094b3d9 to your computer and use it in GitHub Desktop.
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
static void translucentStatusBar(Activity activity, boolean hideStatusBarBackground) { | |
Window window = activity.getWindow(); | |
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | |
if (hideStatusBarBackground) {// Remove status bar | |
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); | |
window.setStatusBarColor(Color.TRANSPARENT); | |
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); | |
} else {// Transparent status bar | |
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); | |
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); | |
} | |
ViewGroup mContentView = window.findViewById(Window.ID_ANDROID_CONTENT); | |
View mChildView = mContentView.getChildAt(0); | |
if (mChildView != null) { | |
ViewCompat.setFitsSystemWindows(mChildView, false); | |
ViewCompat.requestApplyInsets(mChildView); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment