搜索Google Play等编辑文字

时间:2015-09-16 04:12:49

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

如何实现搜索编辑文本,例如谷歌播放,使用“取消”和“取消”按钮右侧的语音搜索和建议列表应显示在完整的编辑文本布局下方。

enter image description here

2 个答案:

答案 0 :(得分:3)

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

Actvity就像这样声明了

<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;
 }

答案 1 :(得分:1)

一些很棒的库提供了你想要的搜索视图,例如:
Floating Search View

enter image description here enter image description here

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