3

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.

Parichit
  • 257
  • 4
  • 13
  • **But this messes up the animation of sheet floating upwards from bottom.** Do you mean when the fragment is attached, the bottom sheet _animates_ from bottom to top? – muthuraj Dec 24 '16 at 16:26
  • I'm not sure if you're still looking for an answer, but [this person's solution](http://stackoverflow.com/a/40034863/2229572) works – Caleb Lewis Mar 08 '17 at 22:04

1 Answers1

2

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>
Prince Bansal
  • 1,635
  • 15
  • 24
  • I was just trying up that, the issue is I want to implement it using a separate activity/fragment because I'll be having some local variables and computations which I want to keep isolated to the panel. – Parichit Dec 24 '16 at 13:18
  • No issues. In your panel layout, just add a single FrameLayout. Now make a fragment, fragment layout and inflate it using FragmentManager in the FrameLayout from your activity. This way your panel logic will be in separate class. – Prince Bansal Dec 24 '16 at 13:23
  • I will update the code if you find any difficulties. But if you understand what I'm trying to say then this is good to go. :) – Prince Bansal Dec 24 '16 at 13:24
  • I tried it but I got stuck at another problem. I want to add a seperate toolbar in fragment with menu items and a close button and avoid resetting the activity toolbar. Do you know anyway I can do that? – Parichit Dec 24 '16 at 14:04