fix(dialog): 修复Chip选择对话框的标题显示和布局问题

- 修改对话框确认按钮提示文本,使用动态标题变量替代固定文本
- 移除手动设置Chip的LayoutParams,改为直接使用addView方法
- 设置ChipGroup为多行显示以支持更多选项
- 调整布局文件中ChipGroup的宽度为wrap_content并居中对齐
- 添加水平和垂直间距属性以改善Chip排列效果
- 修正ShelfV3Activity中传递给对话框的标题文本格式
This commit is contained in:
2026-06-26 16:43:45 +08:00
parent 5412f0b6b9
commit 947afd06e8
3 changed files with 9 additions and 9 deletions
@@ -59,7 +59,7 @@ class ChipSelectDialog(context: Context) : Dialog(context, R.style.DialogTheme)
binding.btnConfirm.setOnClickListener {
if (binding.chipGroup.checkedChipId == -1) {
context.toast("请选择净菜分类")
context.toast("请选择$dialogTitle")
return@setOnClickListener
}
onItemSelected?.invoke(selectedIndex)
@@ -99,13 +99,10 @@ class ChipSelectDialog(context: Context) : Dialog(context, R.style.DialogTheme)
selectedIndex = index
}
}
val params = ChipGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT
).apply {
setMargins(8, 5.dp, 8.dp, 5.dp) // left, top, right, bottom
binding.chipGroup.apply {
isSingleLine = false
addView(chip)
}
binding.chipGroup.addView(chip, params)
}
}
}
@@ -358,7 +358,7 @@ class ShelfV3Activity : BaseActivity() {
private fun showChipSelectDialog(categoryList: List<String?>, callback: (Int) -> Unit) {
ChipSelectDialog(this).apply {
dialogTitle = "请选择净菜分类"
dialogTitle = "净菜分类"
items = categoryList
onItemSelected = callback
show()
@@ -27,10 +27,13 @@
<!-- ChipGroup 选择区域 -->
<com.google.android.material.chip.ChipGroup
android:id="@+id/chipGroup"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginHorizontal="30dp"
android:layout_marginVertical="50dp"
app:chipSpacingHorizontal="30dp"
app:chipSpacingVertical="18dp"
app:selectionRequired="false"
app:singleSelection="true" />