gpt4 book ai didi

Android BottomSheetDialogFragment 状态变化监听器

转载 作者:行者123 更新时间:2023-12-03 10:11:31 27 4
gpt4 key购买 nike

我正在使用 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.
我想根据当前状态更改一些 View - 例如当 BottomSheetDialogFragment将扩展全屏,我想在右上角显示十字图标以关闭它等。
我怎么能听到这种事件?

最佳答案

迟到了,但可能是您问题的答案。您必须使用 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;
}
}

关于Android BottomSheetDialogFragment 状态变化监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55248820/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com