Disabling (fading and fading) dialog box animations

I am a novice programmer, and I have a problem with disabling the animation of the dialog box (disappear and disappear).

I tried to use an empty style and set it by changing

final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 

in

 final AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.NoAnimation)); 

The background of the dialog box turned black, positive and negative button presses changed to <2.1 - 4.0) Android style, but the disappearance and disappearance of the animation effect remained ...

My style:

 <style name="DialogNoAnimation"> <item name="android:windowEnterAnimation">@anim/enter</item> <item name="android:windowExitAnimation">@anim/exit</item> </style> <style name="NoAnimation" parent="@android:style/Theme.Dialog"> <item name="android:windowAnimationStyle">@style/DialogNoAnimation</item> </style> 

Any ideas how I can remove this animation?

+6
source share
2 answers

Finally success!

Res / anim / enter.xml

 <?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="@android:integer/config_shortAnimTime"/> 

Res / anim / exit.xml

 <?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="@android:integer/config_shortAnimTime"/> 

RES / values ​​/ styles.xml

 <style name="DialogNoAnimation"> <item name="android:windowEnterAnimation">@anim/enter</item> <item name="android:windowExitAnimation">@anim/exit</item> </style> 

Src / [dialog_box_class] .java

 @Override public void onStart() { super.onStart(); if (getDialog() == null) return; getDialog().getWindow().setWindowAnimations(R.style.DialogNoAnimation); } 
+6
source

here's a simple solution:

Define a custom style in your styles. xml:

 <style name="Dialog"> <item name="android:windowAnimationStyle">@null</item> //... more items </style> 

Create a new creator with your custom style:

 AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.Dialog); builder.setTitle("Dialog title"); builder.show(); 

to use

+2
source

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


All Articles