-
Notifications
You must be signed in to change notification settings - Fork 80
input number dialog API for Java
vincent(朱志强) edited this page Sep 15, 2023
·
4 revisions
- 快速上手
- 详细API
SmartDialog.builderOfInputNumber()
.title("请输入货物件数")
.defaultFilledNumber("5")
.numberUnit("件")
.numberType(NumberType.INTEGER)
.confirmBtnListener(new InputNumberConfirmListener() {
@Override
public void onInputNumberConfirmed(DialogInterface dialog, String number) {
dialog.dismiss();
SmartToast.classic().showInCenter("您选择的件数为:" + number);
}
})
.build(activity)
.show();
监听器可用lambda简写,
SmartDialog.builderOfInputNumber()
.title("请输入货物件数")
.defaultFilledNumber("5")
.numberUnit("件")
.numberType(NumberType.INTEGER)
.confirmBtnListener((InputNumberConfirmListener) (dialog, number) -> {
dialog.dismiss();
SmartToast.classic().showInCenter("您选择的件数为:" + number);
})
.build(activity)
.show();
InputNumberDialogFacade.Handle handle = SmartDialog.builderOfInputNumber()
.title("请输入货物件数")
.defaultFilledNumber("5")
.numberUnit("件")
.numberType(NumberType.INTEGER)
.confirmBtnListener((InputNumberConfirmListener) (dialog, number) -> {
dialog.dismiss();
SmartToast.classic().showInCenter("您选择的件数为:" + number);
})
.build(activity);
//显示
handle.show();
//隐藏
handle.dismiss();
//是否正在显示
handle.isShowing();
SmartDialog.builderOfInputNumber()
.title("title")
.build(activity)
.show();
或者,
SmartDialog.builderOfInputNumber()
.titleResource(R.string.input_number_title)
.build(activity)
.show();
SmartDialog.builderOfInputNumber()
//颜色,大小(单位sp),是否加粗
.titleStyle(Color.BLUE,18f,false)
.build(activity)
.show();
回到目录导航
默认填充的数字并不hint,默认填充数字是指dialog显示时,输入框内默认已填充的数字,可编辑,可删除。
SmartDialog.builderOfInputNumber()
.defaultFilledNumber("5")
.build(activity)
.show();
SmartDialog.builderOfInputNumber()
.hint("请输入货物件数")
.build(activity)
.show();
或者,
SmartDialog.builderOfInputNumber()
.hintResource(R.string.input_hint)
.build(activity)
.show();
回到目录导航
NumberType.INTEGER 整数,
NumberType.DECIMAL 小数
SmartDialog.builderOfInputNumber()
.numberType(NumberType.INTEGER)
.build(activity)
.show();
SmartDialog.builderOfInputNumber()
.numberSigned(false)
.build(activity)
.show();
SmartDialog.builderOfInputNumber()
.numberUnit("件")
.build(activity)
.show();
或者,
SmartDialog.builderOfInputNumber()
.numberUnitResource(R.string.number_unit)
.build(activity)
.show();
回到目录导航
默认为“确定”
SmartDialog.builderOfInputNumber()
.confirmBtnLabel("确定")
.build(activity)
.show();
或者,
SmartDialog.builderOfInputNumber()
.confirmBtnLabelResource(R.string.confirm_btn_label)
.build(activity)
.show();
SmartDialog.builderOfInputNumber()
//颜色,大小(单位sp),是否加粗
.confirmBtnLabelStyle(Color.BLUE,14f,false)
.build(activity)
.show();
SmartDialog.builderOfInputNumber()
.confirmBtnListener(new InputNumberConfirmListener() {
@Override
public void onInputNumberConfirmed(DialogInterface dialog, String number) {
dialog.dismiss();
//do something with number
}
})
.build(activity)
.show();
或者简写为,
SmartDialog.builderOfInputNumber()
.confirmBtnListener((InputNumberConfirmListener) (dialog, number) -> {
dialog.dismiss();
//do something with number
})
.build(activity)
.show();
SmartDialog.builderOfInputNumber()
.cancelBtnLabel("取消")
.build(activity)
.show();
或者,
SmartDialog.builderOfInputNumber()
.cancelBtnLabelResource(R.string.cancel_btn_label)
.build(activity)
.show();
SmartDialog.builderOfInputNumber()
//颜色,大小(单位sp),是否加粗
.cancelBtnLabelStyle(Color.BLUE,14f,false)
.build(activity)
.show();
回到目录导航
可以不设置监听器,默认监听器的效果是隐藏对话框。如想设置监听器,则通过函数confirmBtnListener:
SmartDialog.builderOfInputNumber()
.cancelBtnListener(new CancelBtnListener() {
@Override
public void onCancelBtnClicked(DialogInterface dialog) {
//do something
dialog.dismiss();
}
})
.build(activity)
.show();
或简写为,
SmartDialog.builderOfInputNumber()
.cancelBtnListener((CancelBtnListener) dialog -> {
//do something
dialog.dismiss();
})
.build(activity)
.show();
SmartDialog.builderOfInputNumber()
//默认为true,也就是常见的配置,dialog显示时,周围背景是灰色蒙层
.dimBehind(true)
.build(activity)
.show();
SmartDialog.builderOfInputNumber()
//默认为true
.cancelable(true)
.build(activity)
.show();
SmartDialog.builderOfInputNumber()
//默认false
.cancelOnTouchOutside(false)
.build(activity)
.show();
SmartDialog.builderOfInputNumber()
.dialogShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
//do something
}
})
.build(activity)
.show();
或者简写成,
SmartDialog.builderOfInputNumber()
.dialogShowListener(dialog -> {
//do something
})
.build(activity)
.show();
SmartDialog.builderOfInputNumber()
.dialogDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
//do something
}
})
.build(activity)
.show();
或者简写成,
SmartDialog.builderOfInputNumber()
.dialogDismissListener(dialog -> {
//do something
})
.build(activity)
.show();
SmartDialog.builderOfInputNumber()
.dialogCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
//do something
}
})
.build(activity)
.show();
或者简写为,
SmartDialog.builderOfInputNumber()
.dialogCancelListener(dialog -> {
//do something
})
.build(activity)
.show();
1