I am trying to implement the bottom sheet from google design library. Pressing the button should open the bottom sheet, which covers the entire activity window. For example, when we open an email in Inbox from Gmail. But it must open from below and slide down to leave.
A click on the button should open the bottom sheet and on the slide down or top left. The close button (X) should close the sheet.
I created something like this:
<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>
And I do it like this:
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); } });
However, when I click on the button, the text appears at the bottom. Overlap existing content by default. And there is no black transparent shade behind the bottom sheet.
How can I do it full screen when a button is clicked?
The reason I don't use the fragment is because I have several (many) variables depending on the contents of the bottom sheet. So, if I show the bottom sheet through the fragment, I need to transfer and receive all the data back and forth. To avoid this, I want this to be part of the activity.
Is there any way to achieve this? Thank you for your help.
source share