Parichit
Parichit

Reputation: 257

Full Screen Bottom Sheet Fragment

I have been trying to implement bottom sheet fragment in android and have been unable to scale it to full screen by default. I have even tried to set it's state to STATE_EXPANDED

public void setupDialog(Dialog dialog, int style) {
       super.setupDialog(dialog, style);
       View v = View.inflate(getContext(), R.layout.fragment_my_bottom_sheet_dialog, null);
       dialog.setContentView(v);

       CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) ((View) v.getParent()).getLayoutParams();
       CoordinatorLayout.Behavior behavior = params.getBehavior();

       if (behavior != null && behavior instanceof BottomSheetBehavior) {
           Log.d(TAG, "Inside if");
           ((BottomSheetBehavior) behavior).setState(BottomSheetBehavior.STATE_EXPANDED);
           ((BottomSheetBehavior) behavior).setBottomSheetCallback(mBottomSheetCallback);
       }
   }

But this messes up the animation of sheet floating upwards from bottom. I am trying to create a modal bottom sheet with a full screen and toolbar with a close(X) button like this

Full screen bottom sheet

I would really appreciate if someone could help me out with it.

Upvotes: 3

Views: 5807

Answers (1)

Prince Bansal
Prince Bansal

Reputation: 1655

What I can identify is that you want a Sliding Up Panel to perform setup. I would highly recommend you to use umano's Android Sliding Up Panel library. It has 2 children. One for activity/fragment and other for the panel.

<com.sothree.slidinguppanel.SlidingUpPanelLayout
    xmlns:sothree="http://schemas.android.com/apk/res-auto"
    android:id="@+id/sliding_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom"
    sothree:umanoPanelHeight="68dp"
    sothree:umanoShadowHeight="4dp">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:text="Main Content"
        android:textSize="16sp" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center|top"
        android:text="The Awesome Sliding Up Panel"
        android:textSize="16sp" />
</com.sothree.slidinguppanel.SlidingUpPanelLayout>

Upvotes: 2

Related Questions