【问题标题】:Android close keyboard by pressing 'done' called from a SearchView inside an AlertDialogAndroid 通过按从 AlertDialog 内的 SearchView 调用的“完成”来关闭键盘
【发布时间】: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


【解决方案1】:

可能我没有正确看到您要执行的操作,但我看不到您要在哪里关闭键盘。对于此操作,您有两种选择:

试试看,希望对你有帮助

Close/hide the Android Soft Keyboard with Kotlin

您可以通过不同的方式关闭键盘。我没有看到这个问题更复杂。

我也发现了这个--> How to dismiss keyboard in Android SearchView?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-16
    • 2015-04-06
    • 2020-12-08
    • 2021-01-30
    • 2019-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多