I'm trying to have a custom dialog appear as though it's sliding down from a text view. Is this possible? I can't seem to apply any animation to dialog class. I've tried this line in the constructor, but it has no effect:
this.getWindow().setWindowAnimations(R.anim.paranimation);
I'm not even sure if the animation is correct, but I will be able adjust it once I see what it's doing. I'll list it below for the sake of completeness. I'm not looking for help on the actual animation, just the application to the dialog.
paranimation.xml:
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="-200%"
android:toXDelta="0%"
android:fromYDelta="200%"
android:toYDelta="0%"
android:duration="3000"
android:zAdjustment="top">
</translate>
I meet the same problem,but ,at last I solve the problem by followed way
I have created the Fade in and Fade Out animation for Dialogbox using ChrisJD code.
Inside res/style.xml
Inside anim/fadein.xml
Inside anim/fadeut.xml
MainActivity
First you have to create two animation resources in res/anim
slide_up.xml
slide_bottom.xml
then you have to create a style
and add this line to your class
Based in http://www.devexchanges.info/2015/10/showing-dialog-with-animation-in-android.html
For right to left (entry animation) and left to right (exit animation):
styles.xml:
Create two files in res/anim/:
translate_right_side.xml:
translate_left_side.xml:
In you Fragment/Activity:
I've been struggling with Dialog animation today, finally got it working using styles, so here is an example.
To start with, the most important thing — I probably had it working 5 different ways today but couldn't tell because... If your devices animation settings are set to "No Animations" (Settings → Display → Animation) then the dialogs won't be animated no matter what you do!
The following is a stripped down version of my styles.xml. Hopefully it is self-explanatory. This should be located in
res/values
.The
windowEnterAnimation
is one of my animations and is located inres\anim
. ThewindowExitAnimation
is one of the animations that is part of the Android SDK.Then when I create the Dialog in my activities
onCreateDialog(int id)
method I do the following.Alternatively you could set the animations the following way instead of using the Dialog constructor that takes a theme.