Make bottomSheetDialog full screen over status bar

前端 未结 3 1287
旧巷少年郎
旧巷少年郎 2020-12-13 20:40

I recently used android.support.design.widget.BottomSheetDialogFragment. I wanted to do something which is similar to the Google contact app, its BottomSheet can overlay the

相关标签:
3条回答
  • 2020-12-13 21:05

    Try this. It works for me.

    @Override
    public void setupDialog(Dialog dialog, int style) {
        super.setupDialog(dialog, style);
        View inflatedView = View.inflate(getContext(), R.layout.fragment_coupon, null);
        dialog.setContentView(inflatedView);
    
    
        CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) ((View) inflatedView.getParent()).getLayoutParams();
        CoordinatorLayout.Behavior behavior = params.getBehavior();
    
        if (behavior != null && behavior instanceof BottomSheetBehavior) {
            ((BottomSheetBehavior) behavior).setBottomSheetCallback(mBottomSheetBehaviorCallback);
        }
    
        View parent = (View) inflatedView.getParent();
        parent.setFitsSystemWindows(true);
        BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(parent);
        inflatedView.measure(0, 0);
        DisplayMetrics displaymetrics = new DisplayMetrics();        getActivity().getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
        int screenHeight = displaymetrics.heightPixels;
        bottomSheetBehavior.setPeekHeight(screenHeight);
    
        if (params.getBehavior() instanceof BottomSheetBehavior) {
            ((BottomSheetBehavior)params.getBehavior()).setBottomSheetCallback(mBottomSheetBehaviorCallback);
        }
    
        params.height = screenHeight;
        parent.setLayoutParams(params);
    }
    
    0 讨论(0)
  • 2020-12-13 21:06

    This was easiest and worked for me, just extend BottomSheetDialog and set BottomSheetBehavior to BottomSheetBehavior.STATE_EXPANDED

    Little hack is layout name android.support.design.R.id.design_bottom_sheet is taken from android support design library

    class BottomSheetDialogExpanded(context: Context) : BottomSheetDialog(context) {
    
        private lateinit var mBehavior: BottomSheetBehavior<FrameLayout>
    
        override fun setContentView(view: View) {
            super.setContentView(view)
            val bottomSheet = window.decorView.findViewById<View>(android.support.design.R.id.design_bottom_sheet) as FrameLayout
            mBehavior = BottomSheetBehavior.from(bottomSheet)
            mBehavior.state = BottomSheetBehavior.STATE_EXPANDED
        }
    
        override fun onStart() {
            super.onStart()
            mBehavior.state = BottomSheetBehavior.STATE_EXPANDED
        }
    }
    
    0 讨论(0)
  • 2020-12-13 21:08

    Was not able to find the solution to this problem, but can suggest an alternate that helped me serve the same purpose. Here's the reference : http://www.hidroh.com/2016/06/17/bottom-sheet-everything/

    The article explains creating a bottom sheet activity and adding the backdrop shadow with it.

    0 讨论(0)
提交回复
热议问题