1.自定义AlertDialog并添加动画效果:

2019-04-28  本文已影响0人  BusyBunny

1. 创建AlertDialog:

View view= LayoutInflater.from(RegActivity.this).inflate(R.layout.layout_error_dialog,null);
AlertDialog dialog=new AlertDialog.Builder(RegActivity.this)
                    .setView(view)
                    .create();

2. 添加动画

dialog.getWindow().setWindowAnimations(R.style.mystyle);
dialog.show();

3. style:


<style name="mystyle" parent="@android:style/Animation">
    <item name="android:windowEnterAnimation">@anim/dialog_anim_appear</item>
    <item name="android:windowExitAnimation">@anim/dialog_anim_disappear</item>
</style>

dialog_anim_appear:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:fromXScale="0"
        android:toXScale="1"
        android:fromYScale="0"
        android:toYScale="1"
        android:pivotX="50%p"
        android:pivotY="50%p"
        android:duration="300"
        />
</set>

dialog_anim_disappear:


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

    <alpha
        android:duration="500"
        android:fromAlpha="0.5"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:toAlpha="1.0" />
</set>
上一篇下一篇

猜你喜欢

热点阅读