14

I have a BottomSheetDialogFragment which has two buttons in it and when I click on any button dismiss() method is called. Is there a way by which I can animate BottomSheetDialogFragment. I want it to show a slow sliding down animation with a duration of 1000ms.

Sample code

   signin.findViewById(R.id.signin_button_using).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            callback.onClickSignInEmail();
            dismiss();
        }
    })
Vijay
  • 191
  • 1
  • 1
  • 9
  • Pls. refer this https://stackoverflow.com/questions/19765938/show-and-hide-a-view-with-a-slide-up-down-animation – Pritesh Patel Oct 11 '17 at 17:04
  • @pritesh onClickSignInEmail() takes us to a new fragment. If you understand correctly **BottomSheetDialogFragment** it uses dismiss() to end the bottomsheetdialog and the article you doesn't help – Vijay Oct 11 '17 at 18:00

1 Answers1

38

In your fragment which is extended with BottomSheetDialogFragment, try overriding this method like this

@Override
public void onActivityCreated(Bundle arg0) {
    super.onActivityCreated(arg0);
    getDialog().getWindow()
    .getAttributes().windowAnimations = R.style.DialogAnimation;
}

DialogAnimation can be defined in the styles like this

<style name="DialogAnimation">
    <item name="android:windowEnterAnimation">@anim/slide_up</item>
    <item name="android:windowExitAnimation">@anim/slide_down</item>
</style>

Further, slide_up and slide_down would be your implementation of required animation. You can find plenty of example for the same online.

Ankush Sharma
  • 913
  • 11
  • 20
  • 5
    I have added slide_up and down animation. But it seems like duration is not working. I've also added duration of 1500ms **slide_down.xml** ` ` – Vijay Oct 16 '17 at 17:33
  • link for sample slide animation [link](https://stackoverflow.com/questions/19765938/show-and-hide-a-view-with-a-slide-up-down-animation?noredirect=1&lq=1) – Vijay Oct 16 '17 at 17:37
  • 1
    This animates the whole window, but the visible part – the bottom sheet dialog – is typically much smaller than the window (the remaining space is transparent), so there will be a delay where you're just sliding a transparent view over the background. Turn on Show layout bounds in developer settings to see this in action. I think you should animate the *view* instead. Not sure how yet; working on it. – Nolan Amy Mar 04 '19 at 07:07
  • any help here. I am trying to animate BottomsheetDialogFragment while exit – shyam.y Apr 25 '22 at 03:25