Reputation: 7421
I am trying to implement a bottom sheet from the google design lib. Clicking on a button should open up bottom sheet which covers the whole activity window. Like when we open an email in Inbox by Gmail. But, it should open up from bottom and slide down to dismiss.
Button click should open up bottom sheet and on slide down or top left Close (X) button should close the sheet.
I have set up 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 am intializing 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 a button, the text just appears at the bottom. Overlapping the default existing content. And no black transparent tint behind the bottom sheet.
How can I make it full screen when clicking on button?
The reason I am not using a fragment here is, I have some(many) variables depending on the content of the bottom sheet. So, if I show a bottom sheet via fragment, I need to pass and receive all the data to and fro. To avoid this, I want it to be part of the activity.
Is there any way I can achieve this? Thanks for your help.
Upvotes: 13
Views: 8182
Reputation: 1810
When you click at button you can consider this action like your NestedScrollView container just become visible so it will take place like you write at params
android:layout_width="match_parent"
android:layout_height="wrap_content"
If you want it to take full parent height just use
android:layout_height="match_parent"
If to speak about shadow background like at fragment you can trick that you can set background alpha color for NestedScrollView
android:background="#64000000"
But it is a hack, you can use fragment and just send all information to it from activity and vice versa
Upvotes: -2
Reputation: 21
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mBottomsheet.callOnClick();
}
});
Try this code........
Upvotes: 0