Skip to content

notification dialog API for Java

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

回到API首页

效果图

目录导航

快速上手

创建并显示dialog

回到目录导航

SmartDialog.builderOfNotification()
    .message("I'm a notification")
    .build(activity)
    .show();

复用dialog

回到目录导航

val handle = SmartDialog.builderOfNotification()
    .message("I'm a notification")
    .build(activity);
//显示
handle.show();
//隐藏
handle.dismiss();
//是否正在显示
handle.isShowing();

详细API

设置title

回到目录导航

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

或者,

SmartDialog.builderOfNotification()
.titleResource(R.string.notification_title)
.build(activity)
.show();

设置title的文本风格

回到目录导航

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

设置message

回到目录导航

SmartDialog.builderOfNotification()
.message("I'm a notification")
.build(activity)
.show();

或者,

SmartDialog.builderOfNotification()
.messageResource(R.string.notification)
.build(activity)
.show();

设置message的文本风格

回到目录导航

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

设置确定按钮的文本

回到目录导航

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

或者,

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

设置确定按钮的文本风格

回到目录导航

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

设置确定按钮监听器

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

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

或简写为,

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

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

回到目录导航

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

设置是否可通过BACK键取消

回到目录导航

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

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

回到目录导航

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

dialog显示监听器

回到目录导航

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

或者简写成,

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

dialog隐藏监听器

回到目录导航

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

或者简写成,

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

dialog取消监听器

回到目录导航

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

或者简写为,

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

1

Clone this wiki locally