【问题标题】:Is it possible to configure an EditText (instead of SearchView) for Android search (i.e. the system-assisted search)?是否可以为 Android 搜索(即系统辅助搜索)配置 EditText(而不是 SearchView)?
【发布时间】:2015-11-24 13:51:30
【问题描述】:

我想通过包含 EditText 和按钮的水平 LinearLayout 创建自定义 SearchView。 EditText 是用户输入搜索查询的地方。

通常当我们使用 SearchView 时,我们

  1. 通过将其配置为在清单中接收ACTION_SEARCH 意图来声明可搜索的活动。

  2. 使用清单中的元元素声明我们的可搜索配置文件。

  3. 通过配置 SearchView 为 SearchView 启用系统辅助搜索(其中系统将搜索查询传递给可搜索的活动、提供语音搜索、显示搜索建议等)。这是通过将SearchableInfo 对象传递给它来完成的:

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView(); // 假设当前活动是可搜索活动 searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

问题是,我可以使用我描述的自定义搜索小部件(带有 Edittext 和 Button 的 LinearLayout),并且仍然为它启用系统辅助搜索(通过类似于上面描述的方式)吗?

【问题讨论】:

    标签: android search android-edittext android-custom-view searchview


    【解决方案1】:

    您可以收听编辑文本的 addTextChangedListener 并在每次更改时检查项目列表中的查询字符串。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-15
      • 1970-01-01
      • 2015-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多