gpt4 book ai didi

c# - 如何判断 BottomSheetDialogFragment 何时展开以填满屏幕?

转载 作者:行者123 更新时间:2023-11-29 23:01:38 25 4
gpt4 key购买 nike

我正在尝试遵循 Material Design specification使用 Android 设计支持库将关闭功能可见性工具栏添加到模态底部工作表。

When full-screen, bottom sheets can be internally scrolled to reveal additional content. A toolbar should be used to provide a collapse or close affordance to exit this view.

我使用 BottomSheetBehavior.BottomSheetCallback 根据 BottomSheetBehavior 的展开/折叠状态切换工具栏的可见性。问题是当我尝试向上拖动时工具栏出现,即使 BottomSheetDialogFragment 内容无法填满整个屏幕。当底部工作表展开时,如何判断底部工作表何时全屏显示?

public class BottomSheetToolbarToggleCallback : BottomSheetBehavior.BottomSheetCallback
{
public BottomSheetToolbarToggleCallback(BottomSheetDialogFragment bottomSheetDialogFragment)
{
this.bottomSheetDialogFragment = bottomSheetDialogFragment ?? throw new System.ArgumentNullException(nameof(bottomSheetDialogFragment));
}

public override void OnSlide(View bottomSheet, float slideOffset)
{
}

public override void OnStateChanged(View bottomSheet, int newState)
{
switch (newState)
{
case BottomSheetBehavior.StateCollapsed:
ShowToolbar(bottomSheet, ViewStates.Gone);
break;
case BottomSheetBehavior.StateExpanded:
ShowToolbar(bottomSheet, ViewStates.Visible);
break;
case BottomSheetBehavior.StateHidden:
bottomSheetDialogFragment.Dismiss();
break;
}
}

private void ShowToolbar(View bottomSheet, ViewStates viewState)
{
var toolbar = bottomSheet.FindViewById<Toolbar>(Resource.Id.toolbar);
if (toolbar != null)
{
toolbar.Visibility = viewState;
}
}

private readonly BottomSheetDialogFragment bottomSheetDialogFragment;
}
public abstract class BaseBottomSheetDialogFragment<TViewModel> : MvxBottomSheetDialogFragment<TViewModel> where TViewModel : BaseViewModel
{
protected BaseBottomSheetDialogFragment()
{
}

protected BaseBottomSheetDialogFragment(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
{
}

public override void SetupDialog(Dialog dialog, int style)
{
base.SetupDialog(dialog, style);

this.EnsureBindingContextIsSet(); // This is required to use this.BindingInflate()
var view = this.BindingInflate(LayoutResourceId, null);
dialog.SetContentView(view);

// Add support to handle material design specification to dynamically show a toolbar with an 'X' button.
var layoutParams = (CoordinatorLayout.LayoutParams)((View)view.Parent).LayoutParameters;
var behavior = layoutParams.Behavior;
if (behavior != null && behavior is BottomSheetBehavior)
{
var toolbar = view.FindViewById<Toolbar>(Droid.Resource.Id.toolbar);
if (toolbar != null)
{
toolbar.SetNavigationIcon(Droid.Resource.Drawable.clear);
((BottomSheetBehavior)behavior).SetBottomSheetCallback(new BottomSheetToolbarToggleCallback(this));
if (CloseCommand != null)
{
toolbar.SetNavigationOnClickListener(new MvxAsyncCommandOnClickListener(CloseCommand));
}
}
}
}

/// <summary>
/// The Android layout resource id of the layout to show in the modal bottom sheet.
/// </summary>
protected abstract int LayoutResourceId { get; }

/// <summary>
/// Optional <see cref="MvxAsyncCommand"/> to call when the optional toolbar navigation button is clicked.
/// </summary>
protected abstract IMvxAsyncCommand CloseCommand { get; }
}

最佳答案

由于我不知道你的具体代码,这里是我试过的一个简单例子的 fragment :

public View mView;

public override void SetupDialog(Dialog dialog, int style)
{
base.SetupDialog(dialog, style);

this.EnsureBindingContextIsSet(); // This is required to use this.BindingInflate()
mView = this.BindingInflate(LayoutResourceId, null);
dialog.SetContentView(view);
...
}

BottomSheetCallback 中:

public override void OnStateChanged(View bottomSheet, int newState)
{
switch (newState)
{
case BottomSheetBehavior.StateExpanded:
var height = bottomSheetDialogFragment.mView.Height;//need you convert to your BottomSheetDialogFragment
break;
}
}

关于c# - 如何判断 BottomSheetDialogFragment 何时展开以填满屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56906651/

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