How can I implement BottomSheetDialogFragment with fixed height

前端 未结 3 2205
难免孤独
难免孤独 2021-02-20 05:31

I need to implement BottomSheetDialogFragment and face with the problem. I need that my BottomSheetDialogFragment has fixed height. Does anyone has an

3条回答
  •  感动是毒
    2021-02-20 06:13

    You can directly give the fix height by Creating it style.

    in styles.xml

    
    
    
    

    Update :

    BottomSheetDialog dialog = new BottomSheetDialog(this, R.style.BottomSheetDialog);
    dialog.setContentView(R.layout.layout_bottom_sheet);
    dialog.show();
    

    Or Second Approch :

     CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) ((View) contentView.getParent()).getLayoutParams();
        CoordinatorLayout.Behavior behavior = params.getBehavior();
    
        if( behavior != null && behavior instanceof BottomSheetBehavior ) {
            ((BottomSheetBehavior) behavior).setBottomSheetCallback(mBottomSheetBehaviorCallback);
            ((BottomSheetBehavior) behavior).setPeekHeight(300);
        }
    

提交回复
热议问题