/** * set StatusBarColor * * 1. set Flags to call setStatusBarColor * 2. call setSystemUiVisibility to clear translucentStatusBar's Flag. * 3. set FitsSystemWindows to false */ static void setStatusBarColor(Activity activity, int statusColor) { Window window = activity.getWindow(); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(statusColor); window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT); View mChildView = mContentView.getChildAt(0); if (mChildView != null) { ViewCompat.setFitsSystemWindows(mChildView, false); ViewCompat.requestApplyInsets(mChildView); } }
/** * translucentStatusBar(full-screen) * * 1. set Flags to full-screen * 2. set FitsSystemWindows to false * * @param hideStatusBarBackground hide statusBar's shadow */ static void translucentStatusBar(Activity activity, boolean hideStatusBarBackground) { Window window = activity.getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); if (hideStatusBarBackground) { 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 { window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); } ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT); View mChildView = mContentView.getChildAt(0); if (mChildView != null) { ViewCompat.setFitsSystemWindows(mChildView, false); ViewCompat.requestApplyInsets(mChildView); } }
/** * translucentStatusBar * * 1. set Window Flag : WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS * 2. removeFakeStatusBarViewIfExist * 3. removeMarginTopOfContentChild * 4. cancel ContentChild's fitsSystemWindow */ static void translucentStatusBar(Activity activity) { Window window = activity.getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); ViewGroup mContentView = (ViewGroup) activity.findViewById(Window.ID_ANDROID_CONTENT); View mContentChild = mContentView.getChildAt(0); removeFakeStatusBarViewIfExist(activity); removeMarginTopOfContentChild(mContentChild, getStatusBarHeight(activity)); if (mContentChild != null) { ViewCompat.setFitsSystemWindows(mContentChild, false); } }
/** * set StatusBarColor * * 1. set Window Flag : WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS * 2. removeFakeStatusBarViewIfExist * 3. addFakeStatusBarView * 4. addMarginTopToContentChild * 5. cancel ContentChild's fitsSystemWindow */ static void setStatusBarColor(Activity activity, int statusColor) { Window window = activity.getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT); View mContentChild = mContentView.getChildAt(0); int statusBarHeight = getStatusBarHeight(activity); removeFakeStatusBarViewIfExist(activity); addFakeStatusBarView(activity, statusColor, statusBarHeight); addMarginTopToContentChild(mContentChild, statusBarHeight); if (mContentChild != null) { ViewCompat.setFitsSystemWindows(mContentChild, false); } }
View mChildView = mContentView.getChildAt(0); if (mChildView != null) { ViewCompat.setFitsSystemWindows(mChildView, false); ViewCompat.requestApplyInsets(mChildView);
ViewCompat.setFitsSystemWindows(this, typedArray.getBoolean(R.styleable.MaterialSearchView_android_fitsSystemWindows, false));
R.styleable.DrawerNavigationView_elevation, 0)); ViewCompat.setFitsSystemWindows(this, a.getBoolean(R.styleable.DrawerNavigationView_android_fitsSystemWindows, false));