Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add animation to BottomSheetDialogFragment

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();
        }
    })
like image 536
Vijay Avatar asked Oct 11 '17 17:10

Vijay


1 Answers

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.

like image 171
Ankush Sharma Avatar answered Sep 28 '22 18:09

Ankush Sharma