create animated dialog

Showing posts with label create animated dialog. Show all posts
Showing posts with label create animated dialog. Show all posts

Wednesday, August 6, 2014

Creating animated dialog in android…..


This article shows you to create animated dialog in android.

1- Create anim folder inside resoures(res).

2- Create xml for slide in dialog(slide_in.xml) in anim.

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:fromYDelta="100%p"
    android:toYDelta="0%p" />

3- Create xml for slide out dialog(slide_out.xml) in anim.


<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:fromYDelta="0%p"
    android:toYDelta="100%p" />

4- Create style for animation in styles.xml.

<style name="DialogAnimation">
        <item name="android:windowEnterAnimation">@anim/slide_in</item>
        <item name="android:windowExitAnimation">@anim/slide_out</item>
</style>

<style name="AnimatedDialogTheme" parent="@android:style/Theme.Panel">
        <item name="android:windowAnimationStyle">@style/DialogAnimation</item>
</style>

5- In Java file initialize dialog as-

//Use try catch to avoid Exception in lower api devices
try {
dialog = new Dialog(this, R.style.AnimatedDialogTheme);
} catch(Exception ex) {
dialog = new Dialog(this);
}