12

我正在尝试从谷歌设计库中实现一个底页。单击按钮应打开覆盖整个活动窗口的底部工作表。就像我们在 Inbox by 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);
        }
    });

但是,当我单击一个按钮时,文本只会出现在底部。重叠默认的现有内容。并且底片后面没有黑色透明色调。

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

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

有什么办法可以做到这一点?谢谢你的帮助。

4

2 回答 2

0
mButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        mBottomsheet.callOnClick();
    }
});

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

于 2016-08-08T09:55:42.367 回答
-2

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

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

如果您希望它采用完整的父高度,只需使用

android:layout_height="match_parent"

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

android:background="#64000000"

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

于 2017-03-03T09:22:28.683 回答