Search Edit Text like Google Play

Krishnakant picture Krishnakant · Sep 16, 2015 · Viewed 8.1k times · Source

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.

enter image description here

Answer

QAMAR picture QAMAR · Sep 16, 2015

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