android.support.v4.view.ViewCompat#requestApplyInsets ( )源码实例Demo

下面列出了android.support.v4.view.ViewCompat#requestApplyInsets ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: FimiX8-RE   文件: StatusBarCompatLollipop.java
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);
    }
}
 
源代码2 项目: FimiX8-RE   文件: StatusBarCompatLollipop.java
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);
}
 
源代码3 项目: MeiBaseModule   文件: EyesKitKat.java
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);
    }
}
 
源代码4 项目: MeiBaseModule   文件: EyesLollipop.java
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);
    }
}
 
源代码5 项目: MeiBaseModule   文件: EyesLollipop.java
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);
    }
}
 
源代码6 项目: QPM   文件: StatusBarColorUtils.java
@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);
    }
}
 
源代码7 项目: Common   文件: StatusBarCompatLollipop.java
/**
 * 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);
    }
}
 
源代码8 项目: Common   文件: StatusBarCompatLollipop.java
/**
 * 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);
    }
}
 
源代码9 项目: ticdesign   文件: CoordinatorLayout.java
@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;
}
 
源代码10 项目: scene   文件: Scene.java
@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;
}
 
源代码11 项目: MeiBaseModule   文件: Eyes.java
/**
 * @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);
            }
        }
    }
}
 
源代码12 项目: Floaty   文件: Floaty.java
@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    if (mOnAttachStateChangeListener != null) {
        mOnAttachStateChangeListener.onViewAttachedToWindow(this);
    }

    ViewCompat.requestApplyInsets(this);
}
 
源代码13 项目: Floaty   文件: Stage.java
@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    if (onAttachStateChangeListener != null) {
        onAttachStateChangeListener.onViewAttachedToWindow(this);
    }

    ViewCompat.requestApplyInsets(this);
}
 
源代码14 项目: meiShi   文件: VideoPlayActivity.java
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();
}
 
/**
 * 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);
      }
    }
  }
}
 
源代码16 项目: youqu_master   文件: StatusBarCompat.java
/**
 * 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);
            }
        }
    }
}
 
@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);
  }
}
 
源代码18 项目: LeisureRead   文件: StatusBarCompat.java
/**
 * 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);
      }
    }
  }
}
 
源代码19 项目: MoeQuest   文件: StatusBarCompat.java
/**
 * 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);
      }
    }
  }
}
 
源代码20 项目: GalleryLayoutManager   文件: StatusBarCompat.java
/**
 * 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);
            }
        }
    }
}
 
 同类方法