-
Notifications
You must be signed in to change notification settings - Fork 80
chosen list dialog API for Kotlin
vincent(朱志强) edited this page Sep 15, 2023
·
6 revisions
- 快速上手
- 详细API
SmartDialog.builderOfChosenList()
.title("请选择语言")
.items(listOf("Java", "Kotlin", "C", "C++", "C#", "Html"))
.confirmBtnListener { dialog, chosenItems ->
dialog.dismiss()
SmartToast.classic().showInCenter(chosenItems.toString())
}
.build(activity)
.show()
val handle = SmartDialog.builderOfChosenList()
.title("请选择语言")
.items(listOf("Java", "Kotlin", "C", "C++", "C#", "Html"))
.confirmBtnListener { 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(listOf("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(listOf(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 { 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 {
//do something
it.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 {
//do something
}
.build(activity)
.show()
SmartDialog.builderOfChosenList()
.dialogDismissListener {
//do something
}
.build(activity)
.show()
SmartDialog.builderOfChosenList()
.dialogCancelListener {
//do something
}
.build(activity)
.show()
1