美文网首页
1.自定义AlertDialog并添加动画效果:

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

作者: BusyBunny | 来源:发表于2019-04-28 22:32 被阅读0次

    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>
    

    相关文章

      网友评论

          本文标题:1.自定义AlertDialog并添加动画效果:

          本文链接:https://www.haomeiwen.com/subject/qyysnqtx.html