fix(home): 修复搜索框自动弹起键盘及H5搜索参数名错误

onResume 时清除搜索框焦点避免页面返回后键盘自动弹出,清除方法
封装为公共方法避免外部直接访问内部 View;修正 H5 搜索页参数名
searchVal → secrchVal 对齐服务端约定。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
zhanglei
2026-06-30 15:56:07 +08:00
co-authored by Claude Opus 4.7
parent b609f07240
commit 7a830c3272
2 changed files with 8 additions and 2 deletions
@@ -284,6 +284,7 @@ class HomeFragment :
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
mBinding.healthKnowledgeView.clearSearchFocus()
if (DataStoreManager.isLogin()) { if (DataStoreManager.isLogin()) {
mBinding.tvHi.visibility = View.VISIBLE mBinding.tvHi.visibility = View.VISIBLE
// mBinding.layoutNotice.visibility = View.VISIBLE // mBinding.layoutNotice.visibility = View.VISIBLE
@@ -629,7 +630,7 @@ class HomeFragment :
showToast("网络错误") showToast("网络错误")
return return
} }
val url = "${UrlConfig.getHealthNewsSearchH5Url()}?param=$param&searchVal=$key" val url = "${UrlConfig.getHealthNewsSearchH5Url()}?param=$param&secrchVal=$key"
requireContext().startWebActivity(url, isFull = true, myTitle = "搜索", hideStatus = true) requireContext().startWebActivity(url, isFull = true, myTitle = "搜索", hideStatus = true)
} }
@@ -61,6 +61,7 @@ class HealthKnowledgeView(context: Context?, attrs: AttributeSet?) :
mOnSearchClickListener?.invoke(toString) mOnSearchClickListener?.invoke(toString)
} }
// 键盘搜索键监听 // 键盘搜索键监听
mBinding.searchView.customSearchEt.setOnEditorActionListener { _, actionId, event -> mBinding.searchView.customSearchEt.setOnEditorActionListener { _, actionId, event ->
if (actionId == EditorInfo.IME_ACTION_SEARCH if (actionId == EditorInfo.IME_ACTION_SEARCH
@@ -81,7 +82,6 @@ class HealthKnowledgeView(context: Context?, attrs: AttributeSet?) :
} }
} }
} }
/** /**
* 根据栏目列表设置 TabLayout * 根据栏目列表设置 TabLayout
* @param categories 子栏目列表(健康知识 categoryId=1 的 children * @param categories 子栏目列表(健康知识 categoryId=1 的 children
@@ -143,4 +143,9 @@ class HealthKnowledgeView(context: Context?, attrs: AttributeSet?) :
fun setOnSearchClickListener(listener: (keyword: String) -> Unit) { fun setOnSearchClickListener(listener: (keyword: String) -> Unit) {
mOnSearchClickListener = listener mOnSearchClickListener = listener
} }
// 清除搜索框焦点,防止onResume时自动弹出键盘
fun clearSearchFocus() {
mBinding.searchView.customSearchEt.clearFocus()
}
} }