public OpaqueStatusBarRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); TypedArray ta = context.obtainStyledAttributes( attrs, R.styleable.OpaqueStatusBarRelativeLayout, defStyleAttr, 0); mInsetDrawable = ta.getDrawable(R.styleable.OpaqueStatusBarRelativeLayout_colorPrimaryDark); ta.recycle(); setWillNotDraw(false); ViewCompat.setOnApplyWindowInsetsListener(this, (View v, WindowInsetsCompat insets) -> { mTopInset = insets.getSystemWindowInsetTop(); setPadding(0, mTopInset, 0, 0); ViewCompat.postInvalidateOnAnimation(this); return insets.consumeSystemWindowInsets(); }); setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); }
@Override public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { if (null == mInsets) { mInsets = new Rect(); } mInsets.set(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(), insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom()); setWillNotDraw(mInsetForeground == null); ViewCompat.postInvalidateOnAnimation(ScrimInsetsRelativeLayout.this); if (mOnInsetsCallback != null) { mOnInsetsCallback.onInsetsChanged(insets); } return insets.consumeSystemWindowInsets(); } });
@Override public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { if (null == mInsets) { mInsets = new Rect(); } mInsets.set(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(), insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom()); setWillNotDraw(mInsetForeground == null); ViewCompat.postInvalidateOnAnimation(ScrimInsetsFrameLayout.this); if (mOnInsetsCallback != null) { mOnInsetsCallback.onInsetsChanged(insets); } return insets.consumeSystemWindowInsets(); } });
public DrawerScrimInsetsFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DrawerScrimInsetsFrameLayout, defStyleAttr, R.style.Widget_Drawer_DrawerScrimInsetsFrameLayout); mInsetForeground = a.getDrawable(R.styleable.DrawerScrimInsetsFrameLayout_insetForeground); a.recycle(); setWillNotDraw(true); // No need to draw until the insets are adjusted ViewCompat.setOnApplyWindowInsetsListener(this, (v, insets) -> { if (null == mInsets) { mInsets = new Rect(); } mInsets.set(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(), insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom()); onInsetsChanged(insets); setWillNotDraw(!insets.hasSystemWindowInsets() || mInsetForeground == null); ViewCompat.postInvalidateOnAnimation(DrawerScrimInsetsFrameLayout.this); return insets.consumeSystemWindowInsets(); }); }