隐藏/显示底页中的片段会将底页的状态设置为展开

问题描述

当状态更改为折叠时,我试图隐藏在底页中的片段。

问题是当它隐藏时,底页展开。

如何在不扩大底页的情况下使其消失?

behavior.addBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull View bottomSheet,int newState) {
                if(newState==BottomSheetBehavior.STATE_COLLAPSED){
                    if(fragmentTransaction!=null)
                    {
                        fragmentTransaction=fragmentManager.beginTransaction();
                        fragmentTransaction.hide(fragment).commit();
                    }

                }
            }

解决方法

在下面检查

if(newState==BottomSheetBehavior.STATE_EXPANDED){            
     behavior.setHideable = true
     behavior.setState(BottomSheetBehavior.STATE_COLLAPSED)
}