Using windowTranslucentStatus with CollapsingToolbarLayout

前端 未结 7 1597
南旧
南旧 2020-12-14 06:09

I\'m trying to get a similar effect to what is seen on google play.

I\'ve got the below layout to show a transparent toolbar with an image behind it. When the user s

相关标签:
7条回答
  • 2020-12-14 07:10

    Extend the CoordinatorLayout and call setOnApplyWindowInsetsListener in your constructor to reset inset values. Here is the code:

    public class CustomCoordinatorLayout extends CoordinatorLayout {
        public CustomCoordinatorLayout(Context context) {
            super(context);
            init();
        }
    
        public CustomCoordinatorLayout(Context context, AttributeSet attrs) {
            super(context, attrs);
            init();
        }
    
        public CustomCoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
            init();
        }
    
        private void init() {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
                setOnApplyWindowInsetsListener(new OnApplyWindowInsetsListener() {
                    @Override
                    public WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) {
                        WindowInsets replaced = windowInsets.replaceSystemWindowInsets(0, 0, 0, 0);
                        return replaced;
                    }
                });
            }
        }
    
        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    }
    
    0 讨论(0)
提交回复
热议问题