【问题标题】:Search Edit Text like Google Play像 Google Play 一样搜索编辑文本
【发布时间】:2015-09-16 04:12:48
【问题描述】:

如何实现搜索编辑文本(如 Google play)在语音搜索和建议列表右侧的“返回”和“取消”按钮应显示在完整的编辑文本布局下方。

【问题讨论】:

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


    【解决方案1】:

    这是带有一些自定义的 SearchView 查看文档http://developer.android.com/guide/topics/search/search-dialog.html

    这样声明的活动

    <activity android:name=".SearchableActivity"
              android:launchMode="singleTop" >
        <intent-filter>
            <action android:name="android.intent.action.SEARCH" />
        </intent-filter>
        <meta-data android:name="android.app.searchable"
                          android:resource="@xml/searchable"/>
      </activity>
    

    和 SearchView xml

    <?xml version="1.0" encoding="utf-8"?>
    <searchable xmlns:android="http://schemas.android.com/apk/res/android"
        android:label="@string/search_label"
        android:hint="@string/search_hint"
        android:voiceSearchMode="showVoiceSearchButton|launchRecognizer" >
    </searchable>
    

    您还需要覆盖 onSearchRequested

    @Override
    public boolean onSearchRequested() {
         Bundle appData = new Bundle();
         appData.putBoolean(SearchableActivity.JARGON, true);
         startSearch(null, false, appData, false);
         return true;
     }
    

    【讨论】:

      【解决方案2】:

      有一些很棒的库可以提供您想要的搜索视图,例如:
      Floating Search View

      还有更多:
      https://github.com/lapism/SearchView
      https://github.com/Quinny898/PersistentSearch

      【讨论】:

        猜你喜欢
        • 2021-03-24
        • 1970-01-01
        • 1970-01-01
        • 2021-09-22
        • 1970-01-01
        • 1970-01-01
        • 2015-12-31
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多