Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling (fade in and fade out) dialog box animation

Tags:

android

dialog

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?

like image 814
Stramek Avatar asked Aug 09 '13 19:08

Stramek


2 Answers

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

like image 145
AITAALI_ABDERRAHMANE Avatar answered Sep 19 '22 13:09

AITAALI_ABDERRAHMANE


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);
}
like image 26
Stramek Avatar answered Sep 17 '22 13:09

Stramek