Android 如何从 Material Design 文档中实现 Bottom Sheet

标签 android android-5.0-lollipop material-design floating-action-button

你如何实现底层规范? http://www.google.com/design/spec/components/bottom-sheets.html

Google Drive 的新更新通过按下 float 操作按钮显示了这一点 ->

enter image description here

尽管规范从未提及圆角,但无论是否可行,只是不确定如何去做。当前使用 AppCompat 库,目标设置为 21。

谢谢

最佳答案

编辑

BottomSheet 现在是 android-support-library 的一部分。见 John Shelleys' answer .


不幸的是,目前没有关于如何做到这一点的“官方”方式(至少我知道没有)。
幸运的是,有一个名为 "BottomSheet" (click) 的库它模仿 BottomSheet 的外观和感觉,并支持 Android 2.1 及更高版本。

如果是 Drive 应用,下面是使用这个库的代码:

    new BottomSheet.Builder(this, R.style.BottomSheet_Dialog)
            .title("New")
            .grid() // <-- important part
            .sheet(R.menu.menu_bottom_sheet)
            .listener(new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO
        }
    }).show();

menu_bottom_sheet(基本上是标准的/res/menu/*.xml 资源)

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/folder"
        android:title="Folder"
        android:icon="@drawable/ic_action_folder" />
    <item
        android:id="@+id/upload"
        android:title="Upload"
        android:icon="@drawable/ic_action_file_upload" />
    <item
        android:id="@+id/scan"
        android:title="Scan"
        android:icon="@drawable/ic_action_camera_alt" />
</menu>

输出如下所示:

picture of the bottom sheet

我认为这与原作非常接近。如果您对颜色不满意,可以自定义 - see this (click) .

关于Android 如何从 Material Design 文档中实现 Bottom Sheet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26721403/

相关文章:

android - 如何将新的 conscrypt 库集成到 Android 并默认使用

android - 获取 http ://schemas. android.com/apk/res/android 时出错

java - 无法转换为 DEX 格式

安卓 Material 芯片

android - 当 android studio 3.2 在 3.1.4 上更新时出现 list 合并问题

java - ViewPager 和滑动菜单滑动传播

安卓 Lollipop 联系人颜色

android - 将 Holo Action Bar 保留在 Lollipop 中

android - HttpURLConnection 因 Lollipop 上的 NullPointerException 而失败

reactjs - 什么时候应该在 Material-UI 中使用 Typography?