I'm novice programmist and I have problem with disabling dialog box animation (fade in and fade out).
I tried to to it using empty style and set it by changing
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
into
final AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.NoAnimation));
Background of dialog box became black, positive and negatice button changed into <2.1 - 4.0) android style, but fade in and fade out 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 can I eliminate this animation?
here's a simple solution:
define a custom style on your styles.xml:
<style name="Dialog">
<item name="android:windowAnimationStyle">@null</item>
//... more items
</style>
Create a new builder with your custom style:
AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.Dialog);
builder.setTitle("Dialog title");
builder.show();
enjoy
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With