Show and Hide Bottom Sheet Programmatically

后端 未结 4 696
青春惊慌失措
青春惊慌失措 2020-12-25 10:27

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

   sheet = new BottomSheet.Builder(this,          


        
4条回答
  •  爱一瞬间的悲伤
    2020-12-25 11:22

    Inside your onClick() of the button use: sheet.show().

    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();    
            }
        }
    });
    

提交回复
热议问题