欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Dialog弹出动画

程序员文章站 2022-05-28 22:57:06
...

点击按钮弹出对话框的动画效果

private void showPromptDlg() {
    new PromptDialog(this)
        .setDialogType(PromptDialog.DIALOG_TYPE_SUCCESS)
        .setAnimationEnable(true)
        .setTitleText(getString(R.string.success))
        .setContentText(getString(R.string.text_data))
        .setPositiveListener(getString(R.string.ok), new PromptDialog.OnPositiveListener() {
            @Override
public void onClick(PromptDialog dialog) {
                dialog.dismiss();
}
        }).show();
}

public void showTextDialog(View view) {
    ColorDialog dialog = new ColorDialog(this);
dialog.setColor("#8ECB54");
dialog.setAnimationEnable(true);
dialog.setTitle(getString(R.string.operation));
dialog.setContentText(getString(R.string.content_text));
dialog.setPositiveListener(getString(R.string.text_iknow), new ColorDialog.OnPositiveListener() {
        @Override
public void onClick(ColorDialog dialog) {
            Toast.makeText(MainActivity.this, dialog.getPositiveText().toString(), Toast.LENGTH_SHORT).show();
}
    }).show();
}

public void showPicDialog(View v) {
    ColorDialog dialog = new ColorDialog(this);
dialog.setTitle(getString(R.string.operation));
dialog.setAnimationEnable(true);
dialog.setAnimationIn(getInAnimationTest(this));
dialog.setAnimationOut(getOutAnimationTest(this));
dialog.setContentImage(getResources().getDrawable(R.mipmap.sample_img));
dialog.setPositiveListener(getString(R.string.delete), new ColorDialog.OnPositiveListener() {
        @Override
public void onClick(ColorDialog dialog) {
            Toast.makeText(MainActivity.this, dialog.getPositiveText().toString(), Toast.LENGTH_SHORT).show();
}
    })
    .setNegativeListener(getString(R.string.cancel), new ColorDialog.OnNegativeListener() {
        @Override
public void onClick(ColorDialog dialog) {
            Toast.makeText(MainActivity.this, dialog.getNegativeText().toString(), Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
    }).show();
}

public void showAllModeDialog(View view) {
    ColorDialog dialog = new ColorDialog(this);
dialog.setTitle(getString(R.string.operation));
dialog.setAnimationEnable(true);
dialog.setContentText(getString(R.string.content_text));
dialog.setContentImage(getResources().getDrawable(R.mipmap.sample_img));
dialog.setPositiveListener(getString(R.string.delete), new ColorDialog.OnPositiveListener() {
        @Override
public void onClick(ColorDialog dialog) {
            Toast.makeText(MainActivity.this, dialog.getPositiveText().toString(), Toast.LENGTH_SHORT).show();
}
    })
    .setNegativeListener(getString(R.string.cancel), new ColorDialog.OnNegativeListener() {
        @Override
public void onClick(ColorDialog dialog) {
            Toast.makeText(MainActivity.this, dialog.getNegativeText().toString(), Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
    }).show();
}

public static AnimationSet getInAnimationTest(Context context) {
    AnimationSet out = new AnimationSet(context, null);
AlphaAnimation alpha = new AlphaAnimation(0.0f, 1.0f);
alpha.setDuration(150);
ScaleAnimation scale = new ScaleAnimation(0.6f, 1.0f, 0.6f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scale.setDuration(150);
out.addAnimation(alpha);
out.addAnimation(scale);
    return out;
}

public static AnimationSet getOutAnimationTest(Context context) {
    AnimationSet out = new AnimationSet(context, null);
AlphaAnimation alpha = new AlphaAnimation(1.0f, 0.0f);
alpha.setDuration(150);
ScaleAnimation scale = new ScaleAnimation(1.0f, 0.6f, 1.0f, 0.6f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scale.setDuration(150);
out.addAnimation(alpha);
out.addAnimation(scale);
    return out;
}