Skip to content

acknowledge dialog API for Java

vincent(朱志强) edited this page Sep 15, 2023 · 3 revisions

回到API首页

效果图

目录导航

快速上手

创建并显示dialog

回到目录导航

SmartDialog.builderOfAcknowledge()
        .message("are you sure?")
        .confirmBtnListener(new ConfirmBtnListener() {
            @Override
            public void onConfirmBtnClicked(DialogInterface dialog) {
                dialog.dismiss();
                //do something
            }
        })
        .build(activity)
        .show();

监听器可用lambda简写,

SmartDialog.builderOfAcknowledge()
        .message("are you sure?")
        .confirmBtnListener((ConfirmBtnListener) dialog -> {
            dialog.dismiss();
            //do something
        })
        .build(activity)
        .show();

复用dialog

回到目录导航

AcknowledgeDialogFacade.Handle handle = SmartDialog.builderOfAcknowledge()
        .message("are you sure?")
        .confirmBtnListener((ConfirmBtnListener) dialog -> {
            dialog.dismiss();
            //do something
        })
        .build(activity);
//显示
handle.show();
//隐藏
handle.dismiss();
//是否正在显示
handle.isShowing();

详细API

设置title

回到目录导航

SmartDialog.builderOfAcknowledge()
.title("title")
.build(activity)
.show();

或者,

SmartDialog.builderOfAcknowledge()
.titleResource(R.string.acknowledge_title)
.build(activity)
.show();

设置title的文本风格

回到目录导航

SmartDialog.builderOfAcknowledge()
//颜色,大小(单位sp),是否加粗
.titleStyle(Color.BLUE,18f,false)
.build(activity)
.show();

设置message

回到目录导航

SmartDialog.builderOfAcknowledge()
.message("are you sure?")
.build(activity)
.show();

或者,

SmartDialog.builderOfAcknowledge()
.messageResource(R.string.acknowledge_message)
.build(activity)
.show();

设置message的文本风格

回到目录导航

SmartDialog.builderOfAcknowledge()
//颜色,大小(单位sp),是否加粗
.messageStyle(Color.RED,14f,false)
.build(activity)
.show();

倒计时启用确认按钮

回到目录导航
单位秒,禁用若干秒后启用,禁用期间无法点击确认按钮,一般用于提示用户慎重操作。

SmartDialog.builderOfAcknowledge()
    .message("开启开发者模式?")
    .delayToConfirm(5)
    .build(activity)
    .show();

设置确定按钮的文本

回到目录导航

SmartDialog.builderOfAcknowledge()
.confirmBtnLabel("确定")
.build(activity)
.show();

或者,

SmartDialog.builderOfAcknowledge()
.confirmBtnLabelResource(R.string.confirm_label)
.build(activity)
.show();

设置确定按钮的文本风格

回到目录导航

SmartDialog.builderOfAcknowledge()
//颜色,大小(单位sp),是否加粗
.confirmBtnLabelStyle(Color.BLUE,14f,false)
.build(activity)
.show();

设置确定按钮监听器

回到目录导航

SmartDialog.builderOfAcknowledge()
        .confirmBtnListener(new ConfirmBtnListener() {
            @Override
            public void onConfirmBtnClicked(DialogInterface dialog) {
                //do something
                dialog.dismiss();
            }
        })
        .build(activity)
        .show();

或简写为,

SmartDialog.builderOfAcknowledge()
        .confirmBtnListener((ConfirmBtnListener) dialog -> {
            //do something
            dialog.dismiss();
        })
        .build(activity)
        .show();

设置取消按钮的文本

回到目录导航

SmartDialog.builderOfAcknowledge()
.cancelBtnLabel("取消")
.build(activity)
.show();

或者,

SmartDialog.builderOfAcknowledge()
.cancelBtnLabelResource(R.string.cancel_label)
.build(activity)
.show();

设置取消按钮的文本风格

回到目录导航

SmartDialog.builderOfAcknowledge()
//颜色,大小(单位sp),是否加粗
.cancelBtnLabelStyle(Color.BLUE,14f,false)
.build(activity)
.show();

设置取消按钮监听器

回到目录导航
可以不设置监听器,默认监听器的效果是隐藏对话框。如想设置监听器,则通过函数confirmBtnListener:

SmartDialog.builderOfAcknowledge()
        .cancelBtnListener(new CancelBtnListener() {
            @Override
            public void onCancelBtnClicked(DialogInterface dialog) {
                //do something
                dialog.dismiss();
            }
        })
        .build(activity)
        .show();

或简写为,

SmartDialog.builderOfAcknowledge()
        .cancelBtnListener((CancelBtnListener) dialog -> {
            //do something
            dialog.dismiss();
        })
        .build(activity)
        .show();

设置是否dim(显示时周围背景是否变暗)

回到目录导航

SmartDialog.builderOfAcknowledge()
//默认为true,也就是常见的配置,dialog显示时,周围背景是灰色蒙层
.dimBehind(true)
.build(activity)
.show();

设置是否可通过BACK键取消

回到目录导航

SmartDialog.builderOfAcknowledge()
//默认为true
.cancelable(true)
.build(activity)
.show();

设置是否可通过触碰周边区域取消dialog

回到目录导航

SmartDialog.builderOfAcknowledge()
//默认false
.cancelOnTouchOutside(false)
.build(activity)
.show();

dialog显示监听器

回到目录导航

SmartDialog.builderOfAcknowledge()
        .dialogShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                //do something
            }
        })
        .build(activity)
        .show();

或者简写成,

SmartDialog.builderOfAcknowledge()
        .dialogShowListener(dialog -> {
            //do something
        })
        .build(activity)
        .show();

dialog隐藏监听器

回到目录导航

SmartDialog.builderOfAcknowledge()
        .dialogDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                //do something   
            }
        })
        .build(activity)
        .show();

或者简写成,

SmartDialog.builderOfAcknowledge()
        .dialogDismissListener(dialog -> {
            //do something   
        })
        .build(activity)
        .show();

dialog取消监听器

回到目录导航

SmartDialog.builderOfAcknowledge()
        .dialogCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                //do something
            }
        })
        .build(activity)
        .show();

或者简写为,

SmartDialog.builderOfAcknowledge()
        .dialogCancelListener(dialog -> {
            //do something
        })
        .build(activity)
        .show();

1

Clone this wiki locally