Set state of BottomSheetDialogFragment to expanded

前端 未结 14 833
有刺的猬
有刺的猬 2020-11-30 19:11

How do you set the state of a fragment extending BottomSheetDialogFragment to expanded using BottomSheetBehavior#setState(STATE_EXPANDED) using the

14条回答
  •  既然无缘
    2020-11-30 19:43

    efeturi's answer is great, however, if you want to use onCreateView() to create your BottomSheet, as opposed to going with onCreateDialog(), here is the code you will need to add under your onCreateView() method:

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        getDialog().setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                BottomSheetDialog d = (BottomSheetDialog) dialog;
                View bottomSheetInternal = d.findViewById(android.support.design.R.id.design_bottom_sheet);
                BottomSheetBehavior.from(bottomSheetInternal).setState(BottomSheetBehavior.STATE_EXPANDED);
            }
        });
        return inflater.inflate(R.layout.your_bottomsheet_content_layout, container, false);
    }
    

提交回复
热议问题