Java Code Examples for android.support.v4.view.ViewCompat#requestApplyInsets()
The following examples show how to use
android.support.v4.view.ViewCompat#requestApplyInsets() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StatusBarCompatLollipop.java From FimiX8-RE with MIT License | 6 votes |
public static void translucentStatusBar(Activity activity, boolean hideStatusBarBackground) { Window window = activity.getWindow(); window.addFlags(Integer.MIN_VALUE); if (hideStatusBarBackground) { window.clearFlags(NTLMConstants.FLAG_UNIDENTIFIED_9); window.setStatusBarColor(0); window.getDecorView().setSystemUiVisibility(FimiAppContext.UI_HEIGHT); } else { window.addFlags(NTLMConstants.FLAG_UNIDENTIFIED_9); window.getDecorView().setSystemUiVisibility(0); } View mChildView = ((ViewGroup) window.findViewById(16908290)).getChildAt(0); if (mChildView != null) { ViewCompat.setOnApplyWindowInsetsListener(mChildView, new OnApplyWindowInsetsListener() { public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { return insets; } }); ViewCompat.setFitsSystemWindows(mChildView, false); ViewCompat.requestApplyInsets(mChildView); } }
Example 2
Source File: StatusBarCompatLollipop.java From FimiX8-RE with MIT License | 6 votes |
public static void setStatusBarColorForCollapsingToolbar(Activity activity, AppBarLayout appBarLayout, CollapsingToolbarLayout collapsingToolbarLayout, Toolbar toolbar, int statusColor) { Window window = activity.getWindow(); window.clearFlags(NTLMConstants.FLAG_UNIDENTIFIED_9); window.addFlags(Integer.MIN_VALUE); window.setStatusBarColor(0); window.getDecorView().setSystemUiVisibility(0); View mChildView = ((ViewGroup) window.findViewById(16908290)).getChildAt(0); if (mChildView != null) { ViewCompat.setOnApplyWindowInsetsListener(mChildView, new OnApplyWindowInsetsListener() { public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { return insets; } }); ViewCompat.setFitsSystemWindows(mChildView, true); ViewCompat.requestApplyInsets(mChildView); } ((View) appBarLayout.getParent()).setFitsSystemWindows(true); appBarLayout.setFitsSystemWindows(true); collapsingToolbarLayout.setFitsSystemWindows(true); collapsingToolbarLayout.getChildAt(0).setFitsSystemWindows(true); toolbar.setFitsSystemWindows(false); collapsingToolbarLayout.setStatusBarScrimColor(statusColor); }
Example 3
Source File: EyesKitKat.java From MeiBaseModule with Apache License 2.0 | 6 votes |
static void translucentStatusBar(Activity activity) { Window window = activity.getWindow(); //设置Window为透明 window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); ViewGroup mContentView = (ViewGroup) activity.findViewById(Window.ID_ANDROID_CONTENT); View mContentChild = mContentView.getChildAt(0); //移除已经存在假状态栏则,并且取消它的Margin间距 removeFakeStatusBarViewIfExist(activity); removeMarginTopOfContentChild(mContentChild, getStatusBarHeight(activity)); if (mContentChild != null) { //fitsSystemWindow 为 false, 不预留系统栏位置. ViewCompat.setFitsSystemWindows(mContentChild, false); ViewCompat.requestApplyInsets(mContentChild); } }
Example 4
Source File: EyesLollipop.java From MeiBaseModule with Apache License 2.0 | 6 votes |
static void setStatusBarColor(Activity activity, int statusColor) { Window window = activity.getWindow(); //取消状态栏透明 window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); //添加Flag把状态栏设为可绘制模式 window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); //设置状态栏颜色 window.setStatusBarColor(statusColor); //设置系统状态栏处于可见状态 window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); //让view不根据系统窗口来调整自己的布局 ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT); View mChildView = mContentView.getChildAt(0); if (mChildView != null) { ViewCompat.setFitsSystemWindows(mChildView, false); ViewCompat.requestApplyInsets(mChildView); } }
Example 5
Source File: EyesLollipop.java From MeiBaseModule with Apache License 2.0 | 6 votes |
static void translucentStatusBar(Activity activity, boolean hideStatusBarBackground) { Window window = activity.getWindow(); //添加Flag把状态栏设为可绘制模式 window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); if (hideStatusBarBackground) { //如果为全透明模式,取消设置Window半透明的Flag window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); //设置状态栏为透明 window.setStatusBarColor(Color.TRANSPARENT); //设置window的状态栏不可见 window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View .SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); } else { //如果为半透明模式,添加设置Window半透明的Flag window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); //设置系统状态栏处于可见状态 window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); } //view不根据系统窗口来调整自己的布局 ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT); View mChildView = mContentView.getChildAt(0); if (mChildView != null) { ViewCompat.setFitsSystemWindows(mChildView, false); ViewCompat.requestApplyInsets(mChildView); } }
Example 6
Source File: StatusBarColorUtils.java From QPM with Apache License 2.0 | 6 votes |
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) private static void setStatusBarColorLollipop(Activity activity, int statusColor) { Window window = activity.getWindow(); //取消状态栏透明 window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); //添加Flag把状态栏设为可绘制模式 window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); //设置状态栏颜色 window.setStatusBarColor(statusColor); //设置系统状态栏处于可见状态 window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); //让view不根据系统窗口来调整自己的布局 ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT); View mChildView = mContentView.getChildAt(0); if (mChildView != null) { mChildView.setFitsSystemWindows(false); ViewCompat.requestApplyInsets(mChildView); } }
Example 7
Source File: StatusBarCompatLollipop.java From Common with Apache License 2.0 | 6 votes |
/** * set StatusBarColor * <p> * 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); } }
Example 8
Source File: StatusBarCompatLollipop.java From Common with Apache License 2.0 | 6 votes |
/** * translucentStatusBar(full-screen) * <p> * 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); } }
Example 9
Source File: CoordinatorLayout.java From ticdesign with Apache License 2.0 | 6 votes |
@Override public void onAttachedToWindow() { super.onAttachedToWindow(); resetTouchBehaviors(); if (mNeedsPreDrawListener) { if (mOnPreDrawListener == null) { mOnPreDrawListener = new OnPreDrawListener(); } final ViewTreeObserver vto = getViewTreeObserver(); vto.addOnPreDrawListener(mOnPreDrawListener); } if ((mLastInsets == null && ViewCompat.getFitsSystemWindows(this)) || !mSystemShapeUpdated) { // We're set to fitSystemWindows but we haven't had any insets yet... // Or we are not updated system shape. // We should request a new dispatch of window insets ViewCompat.requestApplyInsets(this); } mIsAttachedToWindow = true; }
Example 10
Source File: Scene.java From scene with Apache License 2.0 | 5 votes |
@MainThread @CallSuper public void onActivityCreated(@Nullable Bundle savedInstanceState) { Activity activity = requireActivity(); Window window = activity.getWindow(); View decorView = window.getDecorView(); int visibility = decorView.getSystemUiVisibility(); if ((visibility & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) != 0) { ViewCompat.requestApplyInsets(decorView); } else if ((visibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) { ViewCompat.requestApplyInsets(decorView); } mCalled = true; }
Example 11
Source File: Eyes.java From MeiBaseModule with Apache License 2.0 | 5 votes |
/** * @param activity * @param color */ public static void setStatusBarLightMode(Activity activity, int color) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { //判断是否为小米或魅族手机,如果是则将状态栏文字改为黑色 if (MIUISetStatusBarLightMode(activity, true) || FlymeSetStatusBarLightMode(activity, true)) { //设置状态栏为指定颜色 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//5.0 activity.getWindow().setStatusBarColor(color); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {//4.4 //调用修改状态栏颜色的方法 setStatusBarColor(activity, color); } } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { //如果是6.0以上将状态栏文字改为黑色,并设置状态栏颜色 activity.getWindow().setBackgroundDrawableResource(android.R.color.transparent); activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); activity.getWindow().setStatusBarColor(color); //fitsSystemWindow 为 false, 不预留系统栏位置. ViewGroup mContentView = (ViewGroup) activity.getWindow().findViewById(Window.ID_ANDROID_CONTENT); View mChildView = mContentView.getChildAt(0); if (mChildView != null) { ViewCompat.setFitsSystemWindows(mChildView, true); ViewCompat.requestApplyInsets(mChildView); } } } }
Example 12
Source File: Floaty.java From Floaty with Apache License 2.0 | 5 votes |
@Override protected void onAttachedToWindow() { super.onAttachedToWindow(); if (mOnAttachStateChangeListener != null) { mOnAttachStateChangeListener.onViewAttachedToWindow(this); } ViewCompat.requestApplyInsets(this); }
Example 13
Source File: Stage.java From Floaty with Apache License 2.0 | 5 votes |
@Override protected void onAttachedToWindow() { super.onAttachedToWindow(); if (onAttachStateChangeListener != null) { onAttachStateChangeListener.onViewAttachedToWindow(this); } ViewCompat.requestApplyInsets(this); }
Example 14
Source File: VideoPlayActivity.java From meiShi with Apache License 2.0 | 5 votes |
private void initView() { toolbar= (Toolbar) findViewById(R.id.tool_bar); setUpCommonBackTooblBar(R.id.tool_bar, "视频播放"); appBarLayout = (AppBarLayout) findViewById(R.id.appbar); appBarLayout.addOnOffsetChangedListener(this); CollapsingToolbarLayout collapsing_toolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); ViewCompat.requestApplyInsets(collapsing_toolbar); collapsing_toolbar.setTitleEnabled(false); collapsing_toolbar.setExpandedTitleColor(Color.TRANSPARENT); resetCollapsingToolbarLayout(collapsing_toolbar); mVideoPlayHeader = new VideoPlayHeader(this, findViewById(R.id.video_header)); initRecyclerView(); }
Example 15
Source File: StatusBarCompat.java From LeisureRead with Apache License 2.0 | 4 votes |
/** * change to full screen mode * * @param hideStatusBarBackground hide status bar alpha Background when SDK > 21, true if hide it */ public static void translucentStatusBar(Activity activity, boolean hideStatusBarBackground) { Window window = activity.getWindow(); ViewGroup mContentView = (ViewGroup) activity.findViewById(Window.ID_ANDROID_CONTENT); //set child View not fill the system window View mChildView = mContentView.getChildAt(0); if (mChildView != null) { ViewCompat.setFitsSystemWindows(mChildView, false); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { int statusBarHeight = getStatusBarHeight(activity); //First translucent status bar. window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { //After LOLLIPOP just set LayoutParams. window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); if (hideStatusBarBackground) { window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.setStatusBarColor(COLOR_TRANSLUCENT); } else { window.setStatusBarColor(calculateStatusBarColor(COLOR_TRANSLUCENT, DEFAULT_COLOR_ALPHA)); } //must call requestApplyInsets, otherwise it will have space in screen bottom if (mChildView != null) { ViewCompat.requestApplyInsets(mChildView); } } else { ViewGroup mDecorView = (ViewGroup) window.getDecorView(); if (mDecorView.getTag() != null && mDecorView.getTag() instanceof Boolean && (Boolean) mDecorView.getTag()) { mChildView = mDecorView.getChildAt(0); //remove fake status bar view. mContentView.removeView(mChildView); mChildView = mContentView.getChildAt(0); if (mChildView != null) { FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mChildView.getLayoutParams(); //cancel the margin top if (lp != null && lp.topMargin >= statusBarHeight) { lp.topMargin -= statusBarHeight; mChildView.setLayoutParams(lp); } } mDecorView.setTag(false); } } } }
Example 16
Source File: StatusBarCompat.java From GalleryLayoutManager with Apache License 2.0 | 4 votes |
/** * change to full screen mode * @param hideStatusBarBackground hide status bar alpha Background when SDK > 21, true if hide it */ public static void translucentStatusBar(Activity activity, boolean hideStatusBarBackground) { Window window = activity.getWindow(); ViewGroup mContentView = (ViewGroup) activity.findViewById(Window.ID_ANDROID_CONTENT); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { int statusBarHeight = getStatusBarHeight(activity); //First translucent status bar. window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); //set child View not fill the system window View mChildView = mContentView.getChildAt(0); if (mChildView != null) { ViewCompat.setFitsSystemWindows(mChildView, false); //must call requestApplyInsets, otherwise it will have space in screen bottom ViewCompat.requestApplyInsets(mChildView); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { //After LOLLIPOP just set LayoutParams. window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); if (hideStatusBarBackground) { window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.setStatusBarColor(COLOR_TRANSLUCENT); } else { window.setStatusBarColor(calculateStatusBarColor(COLOR_TRANSLUCENT, DEFAULT_COLOR_ALPHA)); } } else { ViewGroup mDecorView = (ViewGroup) window.getDecorView(); if (mDecorView.getTag() != null && mDecorView.getTag() instanceof Boolean && (Boolean) mDecorView.getTag()) { mChildView = mDecorView.getChildAt(0); //remove fake status bar view. mDecorView.removeView(mChildView); mChildView = mContentView.getChildAt(0); if (mChildView != null) { FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mChildView.getLayoutParams(); //cancel the margin top if (lp != null && lp.topMargin >= statusBarHeight) { lp.topMargin -= statusBarHeight; mChildView.setLayoutParams(lp); } } mDecorView.setTag(false); } } } }
Example 17
Source File: StatusBarCompat.java From MoeQuest with Apache License 2.0 | 4 votes |
/** * change to full screen mode * * @param hideStatusBarBackground hide status bar alpha Background when SDK > 21, true if hide it */ public static void translucentStatusBar(Activity activity, boolean hideStatusBarBackground) { Window window = activity.getWindow(); ViewGroup mContentView = (ViewGroup) activity.findViewById(Window.ID_ANDROID_CONTENT); //set child View not fill the system window View mChildView = mContentView.getChildAt(0); if (mChildView != null) { ViewCompat.setFitsSystemWindows(mChildView, false); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { int statusBarHeight = getStatusBarHeight(activity); //First translucent status bar. window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { //After LOLLIPOP just set LayoutParams. window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); if (hideStatusBarBackground) { window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.setStatusBarColor(COLOR_TRANSLUCENT); } else { window.setStatusBarColor(calculateStatusBarColor(COLOR_TRANSLUCENT, DEFAULT_COLOR_ALPHA)); } //must call requestApplyInsets, otherwise it will have space in screen bottom if (mChildView != null) { ViewCompat.requestApplyInsets(mChildView); } } else { ViewGroup mDecorView = (ViewGroup) window.getDecorView(); if (mDecorView.getTag() != null && mDecorView.getTag() instanceof Boolean && (Boolean) mDecorView.getTag()) { mChildView = mDecorView.getChildAt(0); //remove fake status bar view. mContentView.removeView(mChildView); mChildView = mContentView.getChildAt(0); if (mChildView != null) { FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mChildView.getLayoutParams(); //cancel the margin top if (lp != null && lp.topMargin >= statusBarHeight) { lp.topMargin -= statusBarHeight; mChildView.setLayoutParams(lp); } } mDecorView.setTag(false); } } } }
Example 18
Source File: DefaultNavigationImplementation.java From native-navigation with MIT License | 4 votes |
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void reconcileStatusBarStyleOnLollipop( final Activity activity, ReadableMap prev, ReadableMap next, boolean firstCall ) { if (firstCall || numberHasChanged("statusBarColor", prev, next)) { boolean animated = false; if (next.hasKey("statusBarAnimation")) { animated = !("none".equals(next.getString("statusBarAnimation"))); } Integer color = defaults.statusBarColor; if (next.hasKey("statusBarColor")) { color = next.getInt("statusBarColor"); } if (animated) { int curColor = activity.getWindow().getStatusBarColor(); ValueAnimator colorAnimation = ValueAnimator.ofObject( new ArgbEvaluator(), curColor, color); colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { activity.getWindow().setStatusBarColor((Integer) animator.getAnimatedValue()); } }); colorAnimation .setDuration(300) .setStartDelay(0); colorAnimation.start(); } else { activity.getWindow().setStatusBarColor(color); } } if (firstCall || boolHasChanged("statusBarTranslucent", prev, next)) { boolean translucent = defaults.statusBarTranslucent; if (next.hasKey("statusBarTranslucent")) { translucent = next.getBoolean("statusBarTranslucent"); } View decorView = activity.getWindow().getDecorView(); // If the status bar is translucent hook into the window insets calculations // and consume all the top insets so no padding will be added under the status bar. if (translucent) { decorView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() { @Override public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) { WindowInsets defaultInsets = v.onApplyWindowInsets(insets); return defaultInsets.replaceSystemWindowInsets( defaultInsets.getSystemWindowInsetLeft(), 0, defaultInsets.getSystemWindowInsetRight(), defaultInsets.getSystemWindowInsetBottom()); } }); } else { decorView.setOnApplyWindowInsetsListener(null); } ViewCompat.requestApplyInsets(decorView); } }
Example 19
Source File: StatusBarCompat.java From youqu_master with Apache License 2.0 | 4 votes |
/** * change to full screen mode * @param hideStatusBarBackground hide status bar alpha Background when SDK > 21, true if hide it */ public static void translucentStatusBar(Activity activity, boolean hideStatusBarBackground) { Window window = activity.getWindow(); ViewGroup mContentView = (ViewGroup) activity.findViewById(Window.ID_ANDROID_CONTENT); //set child View not fill the system window View mChildView = mContentView.getChildAt(0); if (mChildView != null) { ViewCompat.setFitsSystemWindows(mChildView, false); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { int statusBarHeight = getStatusBarHeight(activity); //First translucent status bar. window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { //After LOLLIPOP just set LayoutParams. window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); if (hideStatusBarBackground) { window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.setStatusBarColor(COLOR_TRANSLUCENT); } else { window.setStatusBarColor(calculateStatusBarColor(COLOR_TRANSLUCENT, DEFAULT_COLOR_ALPHA)); } //must call requestApplyInsets, otherwise it will have space in screen bottom if (mChildView != null) { ViewCompat.requestApplyInsets(mChildView); } } else { ViewGroup mDecorView = (ViewGroup) window.getDecorView(); if (mDecorView.getTag() != null && mDecorView.getTag() instanceof Boolean && (Boolean)mDecorView.getTag()) { mChildView = mDecorView.getChildAt(0); //remove fake status bar view. mContentView.removeView(mChildView); mChildView = mContentView.getChildAt(0); if (mChildView != null) { FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mChildView.getLayoutParams(); //cancel the margin top if (lp != null && lp.topMargin >= statusBarHeight) { lp.topMargin -= statusBarHeight; mChildView.setLayoutParams(lp); } } mDecorView.setTag(false); } } } }
Example 20
Source File: StatusBarCompat.java From gank.io-unofficial-android-client with Apache License 2.0 | 4 votes |
/** * change to full screen mode * * @param hideStatusBarBackground hide status bar alpha Background when SDK > 21, true if hide it */ public static void translucentStatusBar(Activity activity, boolean hideStatusBarBackground) { Window window = activity.getWindow(); ViewGroup mContentView = (ViewGroup) activity.findViewById(Window.ID_ANDROID_CONTENT); //set child View not fill the system window View mChildView = mContentView.getChildAt(0); if (mChildView != null) { ViewCompat.setFitsSystemWindows(mChildView, false); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { int statusBarHeight = getStatusBarHeight(activity); //First translucent status bar. window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { //After LOLLIPOP just set LayoutParams. window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); if (hideStatusBarBackground) { window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.setStatusBarColor(COLOR_TRANSLUCENT); } else { window.setStatusBarColor(calculateStatusBarColor(COLOR_TRANSLUCENT, DEFAULT_COLOR_ALPHA)); } //must call requestApplyInsets, otherwise it will have space in screen bottom if (mChildView != null) { ViewCompat.requestApplyInsets(mChildView); } } else { ViewGroup mDecorView = (ViewGroup) window.getDecorView(); if (mDecorView.getTag() != null && mDecorView.getTag() instanceof Boolean && (Boolean) mDecorView.getTag()) { mChildView = mDecorView.getChildAt(0); //remove fake status bar view. mContentView.removeView(mChildView); mChildView = mContentView.getChildAt(0); if (mChildView != null) { FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mChildView.getLayoutParams(); //cancel the margin top if (lp != null && lp.topMargin >= statusBarHeight) { lp.topMargin -= statusBarHeight; mChildView.setLayoutParams(lp); } } mDecorView.setTag(false); } } } }