Skip to content

Instantly share code, notes, and snippets.

@zakrodionov
Forked from jasco/DialogFragAnim_snippet.java
Last active June 13, 2019 12:09
Show Gist options
  • Save zakrodionov/21d090eee43d8357fc2aed0b4609c561 to your computer and use it in GitHub Desktop.
Save zakrodionov/21d090eee43d8357fc2aed0b4609c561 to your computer and use it in GitHub Desktop.
DialogFragment enter/exit animations #view #animation
// example courtesy of http://adilatwork.blogspot.com/2012/11/android-dialogfragment-enter-and-exit.html
// file location: src/main/java/com/example/
@Override
public void onStart() {
super.onStart();
// safety check
if (getDialog() == null) {
return;
}
// set the animations to use on showing and hiding the dialog
getDialog().getWindow().setWindowAnimations(
R.style.dialog_animation_fade);
// alternative way of doing it
//getDialog().getWindow().getAttributes().
// windowAnimations = R.style.dialog_animation_fade;
// ... other stuff you want to do in your onStart() method
}
<?xml version="1.0" encoding="utf-8"?>
<!--
courtesy of http://adilatwork.blogspot.com/2012/11/android-dialogfragment-enter-and-exit.html
file location: src/main/res/anim
-->
<alpha
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="400" />
<?xml version="1.0" encoding="utf-8"?>
<!--
courtesy of http://adilatwork.blogspot.com/2012/11/android-dialogfragment-enter-and-exit.html
file location: src/main/res/anim
-->
<alpha
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator"
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="400" />
<?xml version="1.0" encoding="utf-8"?>
<!--
courtesy of http://adilatwork.blogspot.com/2012/11/android-dialogfragment-enter-and-exit.html
file location: src/main/res/values
-->
<style
name="dialog_animation_fade" >
<item name="android:windowEnterAnimation">@anim/fade_in_dialog</item>
<item name="android:windowExitAnimation">@anim/fade_out_dialog</item>
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment