-
Notifications
You must be signed in to change notification settings - Fork 80
chosen list dialog API for Java
vincent(朱志强) edited this page Sep 15, 2023
·
3 revisions
- 快速上手
- 详细API
SmartDialog.builderOfChosenList()
.title("请选择语言")
.items(Arrays.asList("Java", "Kotlin", "C", "C++", "C#", "Html"))
.confirmBtnListener(new ItemChosenListener() {
@Override
public void onItemChosen(DialogInterface dialog, List<ChosenItem> chosenItems) {
dialog.dismiss();
SmartToast.classic().showInCenter(chosenItems.toString());
}
})
.build(activity)
.show();
监听器可用lambda简写,
SmartDialog.builderOfChosenList()
.title("请选择语言")
.items(Arrays.asList("Java", "Kotlin", "C", "C++", "C#", "Html"))
.confirmBtnListener((ItemChosenListener) (dialog, chosenItems) -> {
dialog.dismiss();
SmartToast.classic().showInCenter(chosenItems.toString());
})
.build(activity)
.show();
ChosenListDialogFacade.Handle handle = SmartDialog.builderOfChosenList()
.title("请选择语言")
.items(Arrays.asList("Java", "Kotlin", "C", "C++", "C#", "Html"))
.confirmBtnListener((ItemChosenListener) (dialog, chosenItems) -> {
dialog.dismiss();
SmartToast.classic().showInCenter(chosenItems.toString());
})
.build(activity);
//显示
handle.show();
//隐藏
handle.dismiss();
//是否正在显示
handle.isShowing();
SmartDialog.builderOfChosenList()
.title("title")
.build(activity)
.show();
或者,
SmartDialog.builderOfChosenList()
.titleResource(R.string.choose_list_title)
.build(activity)
.show();
SmartDialog.builderOfChosenList()
//颜色,大小(单位sp),是否加粗
.titleStyle(Color.BLUE,18f,false)
.build(activity)
.show();
SmartDialog.builderOfChosenList()
.items(Arrays.asList("Java", "Kotlin", "C", "C++", "C#", "Html"))
.build(activity)
.show();
或者,
SmartDialog.builderOfChosenList()
.itemsResource(R.array.choose_list_items)
.build(activity)
.show();
SmartDialog.builderOfChosenList()
//颜色,大小(sp),是否加粗
.itemLabelStyle(Color.parseColor("#333333"), 14f, false)
.build(activity)
.show();
回到目录导航
默认为false,即靠左
SmartDialog.builderOfChosenList()
.itemCenter(false)
.build(activity)
.show();
SmartDialog.builderOfChosenList()
//默认为true,即单选,false表示多选
.singleChoice(false)
.build(activity)
.show();
回到目录导航
默认选中第一项
SmartDialog.builderOfChosenList()
.defaultChosenPos(Arrays.asList(0))
.build(activity)
.show();
回到目录导航
默认在左侧
SmartDialog.builderOfChosenList()
.iconPosition(IconPosition.LEFT)
.build(activity)
.show();
回到目录导航
默认为R.color.colorPrimary
SmartDialog.builderOfChosenList()
.iconColor(Color.BLUE)
.build(activity)
.show();
或者,
SmartDialog.builderOfChosenList()
.iconColorResource(R.color.colorPrimary)
.build(activity)
.show();
回到目录导航
默认为“确定”
SmartDialog.builderOfChosenList()
.confirmBtnLabel("确定")
.build(activity)
.show();
或者,
SmartDialog.builderOfChosenList()
.confirmBtnLabelResource(R.string.confirm_btn_label)
.build(activity)
.show();
SmartDialog.builderOfChosenList()
//颜色,大小(单位sp),是否加粗
.confirmBtnLabelStyle(Color.BLUE,14f,false)
.build(activity)
.show();
SmartDialog.builderOfChosenList()
.confirmBtnListener(new ItemChosenListener() {
@Override
public void onItemChosen(DialogInterface dialog, List<ChosenItem> chosenItems) {
dialog.dismiss();
//do something with chosenItems
}
})
.build(activity)
.show();
或者简写为,
SmartDialog.builderOfChosenList()
.confirmBtnListener((ItemChosenListener) (dialog, chosenItems) -> {
dialog.dismiss();
//do something with chosenItems
})
.build(activity)
.show();
SmartDialog.builderOfChosenList()
.cancelBtnLabel("取消")
.build(activity)
.show();
或者,
SmartDialog.builderOfChosenList()
.cancelBtnLabelResource(R.string.cancel_btn_label)
.build(activity)
.show();
SmartDialog.builderOfChosenList()
//颜色,大小(单位sp),是否加粗
.cancelBtnLabelStyle(Color.BLUE,14f,false)
.build(activity)
.show();
回到目录导航
可以不设置监听器,默认监听器的效果是隐藏对话框。如想设置监听器,则通过函数confirmBtnListener:
SmartDialog.builderOfChosenList()
.cancelBtnListener(new CancelBtnListener() {
@Override
public void onCancelBtnClicked(DialogInterface dialog) {
//do something
dialog.dismiss();
}
})
.build(activity)
.show();
或者简写成,
SmartDialog.builderOfChosenList()
.cancelBtnListener((CancelBtnListener) dialog -> {
//do something
dialog.dismiss();
})
.build(activity)
.show();
SmartDialog.builderOfChosenList()
//默认为true,也就是常见的配置,dialog显示时,周围背景是灰色蒙层
.dimBehind(true)
.build(activity)
.show();
SmartDialog.builderOfChosenList()
//默认为true
.cancelable(true)
.build(activity)
.show();
SmartDialog.builderOfChosenList()
//默认false
.cancelOnTouchOutside(false)
.build(activity)
.show();
SmartDialog.builderOfChosenList()
.dialogShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
//do something
}
})
.build(activity)
.show();
或者简写成,
SmartDialog.builderOfChosenList()
.dialogShowListener(dialog -> {
//do something
})
.build(activity)
.show();
SmartDialog.builderOfChosenList()
.dialogDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
//do something
}
})
.build(activity)
.show();
或者简写成,
SmartDialog.builderOfChosenList()
.dialogDismissListener(dialog -> {
//do something
})
.build(activity)
.show();
SmartDialog.builderOfChosenList()
.dialogCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
//do something
}
})
.build(activity)
.show();
或者简写为,
SmartDialog.builderOfChosenList()
.dialogCancelListener(dialog -> {
//do something
})
.build(activity)
.show();
1