【发布时间】:2020-06-04 02:30:50
【问题描述】:
从片段中,我在 AlertDialog 中使用 SearchView,我希望键盘的“完成”按钮关闭键盘。由于某种原因,它不起作用。
这是我的 AlertDialog"
val mBuilder =
AlertDialog.Builder(context!!, Theme_DeviceDefault_Light_NoActionBar_Fullscreen)
val mView = View.inflate(activity!!, R.layout.list_search, null)
mBuilder.setView(mView)
val dialog = mBuilder.create()
val searchView = view.findViewById<SearchView>(R.id.search_view)
dialog.show()
searchView.setImeOptions(EditorInfo.IME_ACTION_DONE)
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextChange(newText: String): Boolean {
adapterWithSearch.filter(newText)
return true
}
override fun onQueryTextSubmit(query: String): Boolean {
adapterWithSearch.filter(query)
return true
}
})
这是我的 SearchView:
<SearchView
android:id="@+id/searchView"
style="@style/AppTheme.Searches"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:actionViewClass="android.support.v7.widget.SearchView"
android:iconifiedByDefault="false"
android:imeOptions="actionDone"
android:inputType="text"
android:focusable="true"
android:focusableInTouchMode="true"
android:clickable="true" />
我希望关闭键盘,而不是 AlertDialog。 任何人都知道为什么键盘没有被解雇?
【问题讨论】:
-
您要关闭键盘或对话框吗?
-
你想让键盘向下滑动变得不可见吗?
-
我希望关闭键盘,而不是 AlertDialog
-
我编辑了,searchView 是
SearchView对象吗?如果你有一个通用视图,或者我给了另一个帖子的链接,SearchView是一个正确的`SearchView`组件 -
您将在 onQueryTextSubmit 函数中添加一个隐藏键盘的调用。您当前的代码没有这样做。如果你搜索“close keyboard android”,你会发现很多老问题
标签: android android-alertdialog android-softkeyboard searchview