我在底部有一个名为share的按钮,现在我希望只有在状态展开时该按钮才可见,在任何其他状态下按钮都不应该是可见的。这是我试过的代码。
if (mBottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) {share.setVisibility(View.VISIBLE);}
if(mBottomSheetBehavior.getState()==BottomSheetBehavior.STATE_COLLAPSED){share.setVisibility(View.GONE);}
if(mBottomSheetBehavior.getState()==BottomSheetBehavior.STATE_SETTLING){share.setVisibility(View.GONE);}
if(mBottomSheetBehavior.getState()==BottomSheetBehavior.STATE_SETTLING){share.setVisibility(View.GONE);}
但是当我拖动底片进行展开或折叠时没有任何反应,是否有任何我不知道的正确方法
答案 0 :(得分:1)
你可以试试这个
mBottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(View bottomSheet, int newState) {
if (newState == BottomSheetBehavior.STATE_EXPANDED) {
share.setVisibility(View.VISIBLE);
}else{
share.setVisibility(View.GONE);
}
}
@Override
public void onSlide(View bottomSheet, float slideOffset) {
}
});