Java Code Examples for androidx.core.view.ViewCompat#setFitsSystemWindows()

The following examples show how to use androidx.core.view.ViewCompat#setFitsSystemWindows() . 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: SubtitleCollapsingToolbarLayout.java    From collapsingtoolbarlayout-subtitle with Apache License 2.0 6 votes vote down vote up
@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();

    // Add an OnOffsetChangedListener if possible
    final ViewParent parent = getParent();
    if (parent instanceof AppBarLayout) {
        // Copy over from the ABL whether we should fit system windows
        ViewCompat.setFitsSystemWindows(this, ViewCompat.getFitsSystemWindows((View) parent));

        if (onOffsetChangedListener == null) {
            onOffsetChangedListener = new OffsetUpdateListener();
        }
        ((AppBarLayout) parent).addOnOffsetChangedListener(onOffsetChangedListener);

        // We're attached, so lets request an inset dispatch
        ViewCompat.requestApplyInsets(this);
    }
}
 
Example 2
Source File: CollapsingTitleBarLayout.java    From UIWidget with Apache License 2.0 6 votes vote down vote up
@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();

    // Add an OnOffsetChangedListener if possible
    final ViewParent parent = getParent();
    if (parent instanceof AppBarLayout) {
        // Copy over from the ABL whether we should fit system windows
        ViewCompat.setFitsSystemWindows(this, ViewCompat.getFitsSystemWindows((View) parent));

        if (mOnOffsetChangedListener == null) {
            mOnOffsetChangedListener = new OffsetUpdateListener();
        }
        ((AppBarLayout) parent).addOnOffsetChangedListener(mOnOffsetChangedListener);

        // We're attached, so lets request an inset dispatch
        ViewCompat.requestApplyInsets(this);
    }
}
 
Example 3
Source File: CollapsingToolbarLayout.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onAttachedToWindow() {
  super.onAttachedToWindow();

  // Add an OnOffsetChangedListener if possible
  final ViewParent parent = getParent();
  if (parent instanceof AppBarLayout) {
    // Copy over from the ABL whether we should fit system windows
    ViewCompat.setFitsSystemWindows(this, ViewCompat.getFitsSystemWindows((View) parent));

    if (onOffsetChangedListener == null) {
      onOffsetChangedListener = new OffsetUpdateListener();
    }
    ((AppBarLayout) parent).addOnOffsetChangedListener(onOffsetChangedListener);

    // We're attached, so lets request an inset dispatch
    ViewCompat.requestApplyInsets(this);
  }
}
 
Example 4
Source File: StatusBarHelper.java    From monero-wallet-android-app with MIT License 5 votes vote down vote up
public static void setStatusBarColor(Activity activity, int statusColor) {
    Window window = activity.getWindow();
    if (!supportTranslucent()) {
        // 版本小于4.4,绝对不考虑沉浸式
        return;
    }
    // 小米和魅族4.4 以上版本支持沉浸式
    if (DeviceHelper.isMeizu() || DeviceHelper.isMIUI()) {
        window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        return;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        //取消状态栏透明
        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 = 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: StatusBarHelper.java    From monero-wallet-android-app with MIT License 5 votes vote down vote up
public static void translucentStatusBar(Activity activity, boolean hideStatusBarBackground) {
    Window window = activity.getWindow();
    if (!supportTranslucent()) {
        // 版本小于4.4,绝对不考虑沉浸式
        return;
    }
    // 小米和魅族4.4 以上版本支持沉浸式
    if (DeviceHelper.isMeizu() || DeviceHelper.isMIUI()) {
        window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        return;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        //添加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: BottomSheetBehaviorWithInsetsTest.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Test
@SmallTest
public void testFitsSystemWindows() {
  BottomSheetBehaviorWithInsetsActivity activity = activityTestRule.getActivity();
  ViewCompat.setFitsSystemWindows(activity.mCoordinatorLayout, true);
  assertThat(activity.mBehavior.getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
  ViewGroup bottomSheet = activity.mBottomSheet;
  assertThat(
      bottomSheet.getTop(),
      is(activity.mCoordinatorLayout.getHeight() - activity.mBehavior.getPeekHeight()));
  assertThat(activity.mBottomSheetContent.getTop(), is(0));
}
 
Example 7
Source File: StatusBarUtils.java    From CloudReader with Apache License 2.0 5 votes vote down vote up
/**
 * 设置根布局参数
 */
private static void setRootView(Activity activity) {
    ViewGroup rootView = (ViewGroup) ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0);
    //rootview不会为状态栏流出状态栏空间
    ViewCompat.setFitsSystemWindows(rootView,true);
    rootView.setClipToPadding(true);
}