BottomSheetDialog background blinking

前端 未结 3 684
日久生厌
日久生厌 2021-02-01 05:34

BottomSheetDialog\'s background is blinking when switching between apps. What am I doing wrong ?

MainActivity.java

public class MainActi         


        
3条回答
  •  死守一世寂寞
    2021-02-01 05:48

    Use Coordinate layout instead of constraint layout, and define bottomsheet layout in xml like below

        
    
             

    In Java Class Use like this.

        private BottomSheetBehavior mBottomSheetBehavior;
        private View bottomSheet;
        private isBottomSheetExpand = false;
        ...
        btn1.setOnClickListner(new View.OncliView.OnClickListener(){
        @Override
            public void onClick(View v) {
                if(isBottomSheetExpand){
                    openBottomSheet();
                }else{
                    closeBottomSheet();
                }
            }
        });
        ...
        public void closeBottomSheet() {
           if (mBottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) {
                mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
                isBottomSheetExpand = false;
            }
        }
    
        public void openBottomSheet() {
            if (mBottomSheetBehavior.getState() != BottomSheetBehavior.STATE_EXPANDED) {
                mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
                isBottomSheetExpand = true;
            }
        }
    

提交回复
热议问题