- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试遵循 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/
如何制作不覆盖整个屏幕宽度的 BottomSheetDialogFragment(类似于平板电脑上 Chrome 中的“共享方式”工作表)? 最佳答案 正如开发人员在@UfoXp 链接的问题中所建议的
我正在尝试从视频列表中启动 BottomSheetDialogFragment,打开后将播放一个视频,但是我想允许用户在 BottomSheetDialogFragment 打开时从列表中选择其他视频
这个问题在这里已经有了答案: Send data from activity to fragment in Android (22 个回答) 3年前关闭。 我在 RecyclerView 中显示数据.
在我的 BottomSheetDialogFragment 中显示按钮时遇到问题.我希望它粘在我的 Bottom Sheet 的底部,无论这张纸是展开还是折叠。 见下图: (我用草图来创建这个) 任何
Android 的导航组件可以用于在底部表内导航(即在单个底部表中替换/添加 fragment )吗? 我知道如何启动 BottomSheetDialogFragment使用 导航图中的标记。例如下面
我关注了this tutorial在我的 android 应用程序中实现 BottomSheetDiaogFragment。 这是我的 Bottom Sheet 布局(bottom_sheet.xml
我正在尝试将 Algolia 实现为 BottomSheetDialogFragment,并遇到一些我认为与生命周期相关的问题。我试图弄清楚生命周期是什么,但我找不到答案。 如果有明显的原因要四处走走
我正在使用 BottomSheetDialogFragment我需要知道状态何时改变。 例如有 BottomSheetBehavior 的状态 PEEK_HEIGHT_AUTO - Peek at t
我想要实现的是类似于 Instagram 应用内网络浏览器,在您点击广告时使用: 我所做的是,我使用了 WebView bottomSheetDialogFragment,并覆盖了 onCreateD
似乎 BottomSheetDialogFragment 是用 anchor 编码的,如果您的 fragment 布局的高度超过 360dp onShow() 将导致对话框窥视到 360dp 并且您必
我想在沉浸式模式下显示 BottomSheetDialogFragment。最初导航和状态栏会在显示对话框时显示,但我可以使用下面的代码对其进行排序。但是,当显示或关闭对话框时,导航栏会瞬间闪烁。有没
是否可以使 BottomSheetDialogFragment 不是模态的?这意味着底层内容不会变暗,也不会阻止与其交互。 也许只能通过经典 fragment ? 最佳答案 尝试用这种方式扩展Bott
我有一个 BottomSheetDialogFragment,其中有两个按钮,当我单击任何按钮时,会调用 dismiss() 方法。有没有一种方法可以使 BottomSheetDialogFragme
我需要实现 BottomSheetDialogFragment 并面对这个问题。我需要我的 BottomSheetDialogFragment 具有固定高度。有人知道怎么做吗? 这是我的 fragme
是否可以为包含可 ScrollView (例如 ViewPager 或 NestedScrollView)的 BottomSheetDialogFragment 禁用拖动,这样它就可以'既不被拖上也不
这个问题在这里已经有了答案: Set state of BottomSheetDialogFragment to expanded (20 个答案) 关闭 4 年前。 当我打开 BottomShee
我最近将 BottomSheetDialogFragment 添加到我的应用程序,但它显示 Material Dark 主题的背景颜色为白色。即使我使用 android:background="?an
我正在使用 BottomSheetDialogFragment 并且我正在将右上角/左上角做成圆角并且它工作正常但我注意到在圆角后面,它不透明并且非常烦人。 在下面的屏幕截图中很明显: 如何使它们透明
我正在使用 BottomSheetDialogFragment 来显示一些自定义设置。 要求: 当我单击 BottomSheetDialogFragment 中的任何选项卡时,我会替换该 fragme
因此随着 AppCompat 支持库的 v23.2 版本发布,我决定使用 BottomSheetDialogFragment。当我单击 ListView 中的项目时,我一直试图打开底部工作表(与适配器
我是一名优秀的程序员,十分优秀!