Custom dialog animation programmatically

I would like to install some animations in my user dialog, and I would like to do this programmatically. I know I can do this with xml animation:

<style name="DialogAnimation"> <item name="android:windowEnterAnimation">@anim/slide_up_dialog</item> <item name="android:windowExitAnimation">@anim/slide_out_down</item> </style> Dialog imageDiaglog= new Dialog(MainActivity.this,R.style.DialogAnimation); 

But I would like to do it programmatically. How to configure my programmatically created animations on the Dialog show () and hide () methods?

Thanks.

+6
source share
2 answers

You cannot, because the dialog uses a style element to transition the animation. And you cannot set style elements programmatically.

+1
source

You can use DialogFragment and set the animation to onCreateDialog(Dialog) or onStart() . An example from here :

 @Override public Dialog onCreateDialog(Bundle savedInstanceState) { Dialog dialog = super.onCreateDialog(savedInstanceState); dialog.getWindow().getAttributes().windowAnimations = R.style.detailDialogAnimation; return dialog; } 
0
source

Source: https://habr.com/ru/post/990032/


All Articles