Android BottomSheetDialog

MD 风格的底部弹窗,比自定义 Dialog 或 PopupWindow 使用更简单,功能也更强大,比如可以方便的实现拖拽关闭。 细分来说,分为 BottomSheet、BottomSheetDialog、BottomSheetDialogFragment。

  • BottomSheet:依赖于 CoordinatorLayout 和 BottomSheetBehavior,需要将底部菜单作为CoordinatorLayout 的子 View,并且有三个关键的属性需要其设置。
    • app:layout_behavior="@string/bottom_sheet_behavior":代表这是一个 Bottom Sheet。
    • app:behavior_peekHeight=“66dp”:当关闭时,底部能看到的高度,不显示的话设置为 0 即可。
    • app:behavior_hideable=“true”:当拖拽下拉时,是否能全部隐藏。
  • BottomSheetDialog:不必指定父布局是 CoordinatorLayout。因为在 setContentView 时,自定义布局也是会自动被 CoordinatorLayout 包裹起来。
  • BottomSheetDialogFragment:通过继承 BottomSheetFragment 来实现底部菜单布局,并且根据 Fragment 的生命周期做较多逻辑操作的情况。

BottomSheetDialog

使用起来更灵活。父布局与底部菜单布局正常写即可。

示例:

父布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="" />

        <TextView
            android:id="@+id/plot"
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值