全屏底部工作表,顶部带有关闭 (X) 按钮

问题描述 投票:0回答:3

我正在尝试实现谷歌设计库中的底表。单击按钮应打开覆盖整个活动窗口的底部工作表。就像我们在 Gmail 收件箱中打开电子邮件一样。但是,它应该从底部打开并向下滑动以关闭。

单击按钮应打开底部工作表,向下滑动或左上角的“关闭”(X) 按钮应关闭该工作表。

我已经设置了这样的东西:

<android.support.design.widget.CoordinatorLayout
    .. >

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/bottom_sheet"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/bottom_sheet_behavior">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Hello Bottom Sheet !!" />

    </android.support.v4.widget.NestedScrollView>

    <include layout="@layout/content_my_activity" />

</android.support.design.widget.CoordinatorLayout>

我像这样初始化它:

    mBottomSheet = (NestedScrollView) findViewById(R.id.bottom_sheet);
    mBottomSheetBehavior = BottomSheetBehavior.from(mBottomSheet);
    mButton = (Button) findViewById(R.id.bottom_sheet_button);
    mButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
        }
    });

但是,当我单击按钮时,文本仅出现在底部。与默认的现有内容重叠。底板后面没有黑色透明色调。

如何在点击按钮时使其全屏显示?

我在这里不使用片段的原因是,我有一些(许多)变量,具体取决于底部工作表的内容。因此,如果我通过片段显示底部工作表,我需要来回传递和接收所有数据。为了避免这种情况,我希望它成为活动的一部分。

有什么办法可以实现这个目标吗?感谢您的帮助。

android android-design-library bottom-sheet
3个回答
0
投票
mButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        mBottomsheet.callOnClick();
    }
});

试试这个代码........


0
投票

您可以尝试使用 BottomSheetDialog 来扩展您的布局


-2
投票

当您单击按钮时,您可以考虑此操作,就像您的 NestedScrollView 容器变得可见一样,因此它会像您在参数中编写的那样发生

android:layout_width="match_parent"
android:layout_height="wrap_content"

如果你想让它占据父级的完整高度,只需使用

android:layout_height="match_parent"

如果要谈论像片段一样的阴影背景,您可以欺骗您可以为 NestedScrollView 设置背景 alpha 颜色

android:background="#64000000"

但这是一个黑客,您可以使用片段并将所有信息从活动发送给它,反之亦然

© www.soinside.com 2019 - 2024. All rights reserved.