OStack程序员社区-中国程序员成长平台

标题: android - Show and Hide Bottom Sheet Programmatically [打印本页]

作者: 菜鸟教程小白    时间: 2022-5-24 14:16
标题: android - Show and Hide Bottom Sheet Programmatically

I have implemented Bottom Sheet functionality within my activity in onCreate() using this solution and this library

   sheet = new BottomSheet.Builder(this, R.style.BottomSheet_Dialog)
        .title("New")
        .grid() // <-- important part
        .sheet(R.menu.menu_bottom_sheet)
        .listener(new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        // TODO
    }
}).build();

Now, I would like to Show Bottom sheet, on click of button and in a same way want to hide bottom sheet on click of same button, if already Visible



Best Answer-推荐答案


To close the BottomSheetDialogFragment from inside the fragment you can call:

dismiss();

To show or hide the BottomSheetDialogFragment from the activity you can simply call:

bottomSheetDialogFragment.dismiss();//to hide it
bottomSheetDialogFragment.show(getSupportFragmentManager(),tag);// to show it





欢迎光临 OStack程序员社区-中国程序员成长平台 (http://ostack.cn/) Powered by Discuz! X3.4