-
Notifications
You must be signed in to change notification settings - Fork 80
notification dialog API for Java
vincent(朱志强) edited this page Sep 15, 2023
·
16 revisions
- 快速上手
- 详细API
SmartDialog.builderOfNotification()
.message("I'm a notification")
.build(activity)
.show();
val handle = SmartDialog.builderOfNotification()
.message("I'm a notification")
.build(activity);
//显示
handle.show();
//隐藏
handle.dismiss();
//是否正在显示
handle.isShowing();
SmartDialog.builderOfNotification()
.title("title")
.build(activity)
.show();
或者,
SmartDialog.builderOfNotification()
.titleResource(R.string.notification_title)
.build(activity)
.show();
SmartDialog.builderOfNotification()
//颜色,大小(单位sp),是否加粗
.titleStyle(Color.BLUE,18f,false)
.build(activity)
.show();
SmartDialog.builderOfNotification()
.message("I'm a notification")
.build(activity)
.show();
或者,
SmartDialog.builderOfNotification()
.messageResource(R.string.notification)
.build(activity)
.show();
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();
SmartDialog.builderOfNotification()
//默认为true,也就是常见的配置,dialog显示时,周围背景是灰色蒙层
.dimBehind(true)
.build(activity)
.show();
SmartDialog.builderOfNotification()
//默认为true
.cancelable(true)
.build(activity)
.show();
SmartDialog.builderOfNotification()
//默认false
.cancelOnTouchOutside(false)
.build(activity)
.show();
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();
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();
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