以编程方式显示和隐藏底表 [英] Show and Hide Bottom Sheet Programmatically

查看:69
本文介绍了以编程方式显示和隐藏底表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用解决方案和

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

推荐答案

在按钮的 onClick()内部使用: sheet.show().

然后,当您要关闭它时,请使用 sheet.dismiss();

Then when you want to dismiss it, use sheet.dismiss();

以下是一个可能的解决方案:

Here below a possible solution:

BottomSheet sheet = new BottomSheet.Builder(...).build();
Button button = (Button)findViewById(R.id.mybutton);
button.setOnClickListener(new OnClickListener(){
    @Override
    public void onClick(View v) {
        //you can use isShowing() because BottomSheet inherit from Dialog class
        if (sheet.isShowing()){
            sheet.dismiss();
        } else {
            sheet.show();    
        }
    }
});

这篇关于以编程方式显示和隐藏底表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆