Java Code Examples for androidx.core.view.ViewCompat#requestApplyInsets()
The following examples show how to use
androidx.core.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: TranslucentModalHostView.java From react-native-modal-translucent with MIT License | 6 votes |
public static void setStatusBarTranslucent(Window window, boolean translucent) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { View decorView = window.getDecorView(); if (translucent) { decorView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @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 2
Source File: AppUtils.java From AndroidNavigation with MIT License | 6 votes |
public static void setStatusBarTranslucent(Window window, boolean translucent) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { setRenderContentInShortEdgeCutoutAreas(window, translucent); View decorView = window.getDecorView(); if (translucent) { decorView.setOnApplyWindowInsetsListener((v, insets) -> { WindowInsets defaultInsets = v.onApplyWindowInsets(insets); return defaultInsets.replaceSystemWindowInsets( defaultInsets.getSystemWindowInsetLeft(), 0, defaultInsets.getSystemWindowInsetRight(), defaultInsets.getSystemWindowInsetBottom()); }); } else { decorView.setOnApplyWindowInsetsListener(null); } ViewCompat.requestApplyInsets(decorView); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (translucent) { window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); } else { window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); } ViewCompat.requestApplyInsets(window.getDecorView()); } }
Example 3
Source File: BaseActivity.java From DKVideoPlayer with Apache License 2.0 | 6 votes |
/** * 把状态栏设成透明 */ protected void setStatusBarTransparent() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { View decorView = getWindow().getDecorView(); decorView.setOnApplyWindowInsetsListener((v, insets) -> { WindowInsets defaultInsets = v.onApplyWindowInsets(insets); return defaultInsets.replaceSystemWindowInsets( defaultInsets.getSystemWindowInsetLeft(), 0, defaultInsets.getSystemWindowInsetRight(), defaultInsets.getSystemWindowInsetBottom()); }); ViewCompat.requestApplyInsets(decorView); getWindow().setStatusBarColor(ContextCompat.getColor(this, android.R.color.transparent)); } }
Example 4
Source File: SubtitleCollapsingToolbarLayout.java From collapsingtoolbarlayout-subtitle with Apache License 2.0 | 6 votes |
@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 5
Source File: CollapsingTitleBarLayout.java From UIWidget with Apache License 2.0 | 6 votes |
@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 6
Source File: CollapsingToolbarLayout.java From material-components-android with Apache License 2.0 | 6 votes |
@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 7
Source File: GalleryFragment.java From animation-samples with Apache License 2.0 | 5 votes |
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { ViewCompat.requestApplyInsets(view); mEmptyView = view.findViewById(R.id.progress); mGalleryContent = view.findViewById(R.id.gallery_content); initRecyclerView(view); mAnimateViewSwap = savedInstanceState == null && mGalleries == null; if (mGalleries == null) { new GalleryPresenter(this).getData(); } else { showData(mGalleries); } }
Example 8
Source File: StatusBarHelper.java From monero-wallet-android-app with MIT License | 5 votes |
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 9
Source File: StatusBarHelper.java From monero-wallet-android-app with MIT License | 5 votes |
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 10
Source File: BaseTransientBottomBar.java From material-components-android with Apache License 2.0 | 5 votes |
@Override protected void onAttachedToWindow() { super.onAttachedToWindow(); if (onAttachStateChangeListener != null) { onAttachStateChangeListener.onViewAttachedToWindow(this); } ViewCompat.requestApplyInsets(this); }
Example 11
Source File: CustomLinearLayout.java From Paginize with MIT License | 5 votes |
@Override public void onAttachedToWindow() { super.onAttachedToWindow(); if (!mPaddingSet && ViewCompat.getFitsSystemWindows(this)) { ViewCompat.requestApplyInsets(this); setWillNotDraw(false); mPaddingSet = true; } }
Example 12
Source File: CustomScrollView.java From Paginize with MIT License | 5 votes |
@Override public void onAttachedToWindow() { super.onAttachedToWindow(); if (!mPaddingSet && ViewCompat.getFitsSystemWindows(this)) { ViewCompat.requestApplyInsets(this); setWillNotDraw(false); mPaddingSet = true; } }