Search Edit Text like Google Play

落花浮王杯 提交于 2019-12-22 06:59:54

问题


How to implement Search Edit text like Google play with Back and Cancel button on Right at place of Voice search and suggestions list should display below the complete edit text layout.


回答1:


This is SearchView with some customization check the docs http://developer.android.com/guide/topics/search/search-dialog.html

Actvity declared like this

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

and 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>

Also you would need to override the onSearchRequested

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



回答2:


The are some awesome libraries provide the Search view you want, like:
Floating Search View

And more:
https://github.com/lapism/SearchView
https://github.com/Quinny898/PersistentSearch



来源:https://stackoverflow.com/questions/32599652/search-edit-text-like-google-play

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!