我正在使用BottomSheetDialogFragment
,我需要知道状态何时更改。
例如,状态为BottomSheetBehavior
PEEK_HEIGHT_AUTO - Peek at the 16:9 ratio keyline of its parent.
STATE_COLLAPSED - The bottom sheet is collapsed.
STATE_DRAGGING - The bottom sheet is dragging.
STATE_EXPANDED - The bottom sheet is expanded.
STATE_HIDDEN - The bottom sheet is hidden.
STATE_SETTLING - The bottom sheet is settling.
我想基于当前状态更改某些视图-例如,当BottomSheetDialogFragment
将全屏展开时,我想在右上角显示十字图标以将其关闭等。
我如何收听此类事件?
谢谢。
答案 0 :(得分:0)
后期,但可能是您问题的答案。您必须使用bottomSheetBehavior回调。
bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(View bottomSheet, int newState) {
switch (newState) {
case BottomSheetBehavior.STATE_COLLAPSED:
Log.d("Bottom Sheet Behavior", "STATE_COLLAPSED");
break;
case BottomSheetBehavior.STATE_DRAGGING:
Log.d("Bottom Sheet Behavior", "STATE_DRAGGING");
break;
case BottomSheetBehavior.STATE_EXPANDED:
Log.d("Bottom Sheet Behavior", "STATE_EXPANDED");
break;
case BottomSheetBehavior.STATE_HIDDEN:
Log.d("Bottom Sheet Behavior", "STATE_HIDDEN");
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
break;
case BottomSheetBehavior.STATE_SETTLING:
Log.d("Bottom Sheet Behavior", "STATE_SETTLING");
break;
}
}