2

I know how to change the height of a Bottom Sheet. There is no problem to increase the height of a bottom sheet. However I cannot decrease its height with the following code .

bottomSheetBehavior.setPeekHeight(peekHeight); // peekHeight < previous height
bottomSheetBehavior.setState(STATE_COLLAPSED);

Anyone encountered the same problem ?

Community
  • 1
  • 1
Raymond Chenon
  • 11,482
  • 15
  • 77
  • 110
  • So if you change your peek height after having it set once, it does not get applied? – David Medenjak May 13 '16 at 16:17
  • Have you tried to use BottomSheetBehavior.from(bottomSheet) before you set the peekHeight? you can pass as paramenter your bottomSheet and then add the lines you used above – Ruan_Lopes May 13 '16 at 17:55

1 Answers1

3

I am trying to do the same and I don't have such problem. I could easily increase and decrease my BottomSheetDialogFragment height. Here is my code of two methods of my fragment:

private BottomSheetBehavior.BottomSheetCallback bottomSheetCallback = new BottomSheetBehavior.BottomSheetCallback() {
        @Override
        public void onStateChanged(@NonNull View bottomSheet, int newState) {
            if (newState == BottomSheetBehavior.STATE_HIDDEN) {
                dismiss();
            }
        }

        @Override
        public void onSlide(@NonNull View bottomSheet, float slideOffset) {
        }
    };

    public static BottomSheetFragment newInstance() {
        return new BottomSheetFragment();
    }

    @Override
    public void setupDialog(Dialog dialog, int style) {
        super.setupDialog(dialog, style);
        View contentView = View.inflate(getContext(), R.layout.bottom_sheet_dialog_content_view, null);
        dialog.setContentView(contentView);
        CoordinatorLayout.LayoutParams layoutParams = ((CoordinatorLayout.LayoutParams) ((View) contentView.getParent()).getLayoutParams());
        CoordinatorLayout.Behavior behavior = layoutParams.getBehavior();
        if (behavior != null && behavior instanceof BottomSheetBehavior) {
            ((BottomSheetBehavior) behavior).setBottomSheetCallback(bottomSheetCallback);
            ((BottomSheetBehavior) behavior).setPeekHeight(getResources().getDimensionPixelSize(R.dimen.bottom_sheet_height) / 4);
        }

        initRecyclerView(contentView);
    }