修改dialog 彈出和 隱藏的動畫
阿新 • • 發佈:2018-12-12
首先在dialog 中拿到window 物件 ,然後給window物件設定動畫 上程式碼
Window window = getWindow();
window.setWindowAnimations(R.style.DialogAnimations);
<!-- dialog theme. --> <style name="DialogAnimations" parent="android:Animation"> <item name="android:windowEnterAnimation" >@anim/slide_bottom_in</item> <item name="android:windowExitAnimation" >@anim/slide_bottom_out</item> </style>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="10%p"
android:toYDelta="0%p"
android:duration="300"/>
<alpha
android:fromAlpha="0"
android:toAlpha="1.0"
android:duration="300"/>
</set>
<set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromYDelta="0%p" android:toYDelta="10%p" android:duration="300"/> <alpha android:fromAlpha="1" android:toAlpha="0" android:duration="300"/> </set>