Skip to content

Most visited

Recently visited

navigation

SearchViewCompat

public final class SearchViewCompat
extends Object

java.lang.Object
   ↳ android.support.v4.widget.SearchViewCompat


This class was deprecated in API level 26.0.0.
Use SearchView directly.

Helper for accessing features in SearchView.

Summary

Nested classes

interface SearchViewCompat.OnCloseListener

This interface was deprecated in API level 26.0.0. Use SearchView.OnCloseListener instead.  

class SearchViewCompat.OnCloseListenerCompat

This class was deprecated in API level 24.2.0. Use SearchView.OnCloseListener instead.  

interface SearchViewCompat.OnQueryTextListener

This interface was deprecated in API level 26.0.0. Use SearchView.OnQueryTextListener instead.  

class SearchViewCompat.OnQueryTextListenerCompat

This class was deprecated in API level 24.2.0. Use SearchView.OnQueryTextListener instead.  

Public methods

static CharSequence getQuery(View searchView)

This method was deprecated in API level 26.0.0. Use getQuery() directly.

static boolean isIconified(View searchView)

This method was deprecated in API level 26.0.0. Use isIconified() directly.

static boolean isQueryRefinementEnabled(View searchView)

This method was deprecated in API level 26.0.0. Use isQueryRefinementEnabled() directly.

static boolean isSubmitButtonEnabled(View searchView)

This method was deprecated in API level 26.0.0. Use isSubmitButtonEnabled() directly.

static View newSearchView(Context context)

This method was deprecated in API level 26.0.0. Use SearchView constructor directly.

static void setIconified(View searchView, boolean iconify)

This method was deprecated in API level 26.0.0. Use setIconified(boolean) directly.

static void setImeOptions(View searchView, int imeOptions)

This method was deprecated in API level 26.0.0. Use setImeOptions(int) directly.

static void setInputType(View searchView, int inputType)

This method was deprecated in API level 26.0.0. Use setInputType(int) directly.

static void setMaxWidth(View searchView, int maxpixels)

This method was deprecated in API level 26.0.0. Use setMaxWidth(int) directly.

static void setOnCloseListener(View searchView, SearchViewCompat.OnCloseListener listener)

This method was deprecated in API level 26.0.0. Use setOnCloseListener(SearchView.OnCloseListener) directly.

static void setOnQueryTextListener(View searchView, SearchViewCompat.OnQueryTextListener listener)

This method was deprecated in API level 26.0.0. Use setOnQueryTextListener(SearchView.OnQueryTextListener) directly.

static void setQuery(View searchView, CharSequence query, boolean submit)

This method was deprecated in API level 26.0.0. Use setQuery(CharSequence, boolean) directly.

static void setQueryHint(View searchView, CharSequence hint)

This method was deprecated in API level 26.0.0. Use setQueryHint(CharSequence) directly.

static void setQueryRefinementEnabled(View searchView, boolean enable)

This method was deprecated in API level 26.0.0. Use setQueryRefinementEnabled(boolean) directly.

static void setSearchableInfo(View searchView, ComponentName searchableComponent)

This method was deprecated in API level 26.0.0. Use setSearchableInfo(SearchableInfo) directly.

static void setSubmitButtonEnabled(View searchView, boolean enabled)

This method was deprecated in API level 26.0.0. Use setSubmitButtonEnabled(boolean) directly.

Inherited methods

From class java.lang.Object

Public methods

getQuery

added in version 22.0.0
CharSequence getQuery (View searchView)

This method was deprecated in API level 26.0.0.
Use getQuery() directly.

Returns the query string currently in the text field.

Parameters
searchView View: The SearchView to operate on.

Returns
CharSequence the query string

isIconified

added in version 22.0.0
boolean isIconified (View searchView)

This method was deprecated in API level 26.0.0.
Use isIconified() directly.

Returns the current iconified state of the SearchView.

Parameters
searchView View: The SearchView to operate on.

Returns
boolean true if the SearchView is currently iconified, false if the search field is fully visible.

isQueryRefinementEnabled

added in version 22.0.0
boolean isQueryRefinementEnabled (View searchView)

This method was deprecated in API level 26.0.0.
Use isQueryRefinementEnabled() directly.

Returns whether query refinement is enabled for all items or only specific ones.

Parameters
searchView View: The SearchView to operate on.

Returns
boolean true if enabled for all items, false otherwise.

isSubmitButtonEnabled

added in version 22.0.0
boolean isSubmitButtonEnabled (View searchView)

This method was deprecated in API level 26.0.0.
Use isSubmitButtonEnabled() directly.

Returns whether the submit button is enabled when necessary or never displayed.

Parameters
searchView View: The SearchView to operate on.

Returns
boolean whether the submit button is enabled automatically when necessary

newSearchView

added in version 22.0.0
View newSearchView (Context context)

This method was deprecated in API level 26.0.0.
Use SearchView constructor directly.

Creates a new SearchView.

Parameters
context Context: The Context the view is running in.

Returns
View A SearchView instance if the class is present on the current platform, null otherwise.

setIconified

added in version 22.0.0
void setIconified (View searchView, 
                boolean iconify)

This method was deprecated in API level 26.0.0.
Use setIconified(boolean) directly.

Iconifies or expands the SearchView. Any query text is cleared when iconified. This is a temporary state and does not override the default iconified state set by setIconifiedByDefault(boolean). If the default state is iconified, then a false here will only be valid until the user closes the field. And if the default state is expanded, then a true here will only clear the text field and not close it.

Parameters
searchView View: The SearchView to operate on.

iconify boolean: a true value will collapse the SearchView to an icon, while a false will expand it.

setImeOptions

added in version 22.0.0
void setImeOptions (View searchView, 
                int imeOptions)

This method was deprecated in API level 26.0.0.
Use setImeOptions(int) directly.

Sets the IME options on the query text field. This is a no-op if called on pre-ICE_CREAM_SANDWICH platforms.

Parameters
searchView View: The SearchView to operate on.

imeOptions int: the options to set on the query text field

See also:

setInputType

added in version 22.0.0
void setInputType (View searchView, 
                int inputType)

This method was deprecated in API level 26.0.0.
Use setInputType(int) directly.

Sets the input type on the query text field. This is a no-op if called on pre-ICE_CREAM_SANDWICH platforms.

Parameters
searchView View: The SearchView to operate on.

inputType int: the input type to set on the query text field

See also:

setMaxWidth

added in version 22.0.0
void setMaxWidth (View searchView, 
                int maxpixels)

This method was deprecated in API level 26.0.0.
Use setMaxWidth(int) directly.

Makes the view at most this many pixels wide

Parameters
searchView View: The SearchView to operate on.

maxpixels int

setOnCloseListener

added in version 24.2.0
void setOnCloseListener (View searchView, 
                SearchViewCompat.OnCloseListener listener)

This method was deprecated in API level 26.0.0.
Use setOnCloseListener(SearchView.OnCloseListener) directly.

Sets a listener to inform when the user closes the SearchView.

Parameters
searchView View: The SearchView in which to register the listener.

listener SearchViewCompat.OnCloseListener: the listener to call when the user closes the SearchView.

setOnQueryTextListener

added in version 24.2.0
void setOnQueryTextListener (View searchView, 
                SearchViewCompat.OnQueryTextListener listener)

This method was deprecated in API level 26.0.0.
Use setOnQueryTextListener(SearchView.OnQueryTextListener) directly.

Sets a listener for user actions within the SearchView.

Parameters
searchView View: The SearchView in which to register the listener.

listener SearchViewCompat.OnQueryTextListener: the listener object that receives callbacks when the user performs actions in the SearchView such as clicking on buttons or typing a query.

setQuery

added in version 22.0.0
void setQuery (View searchView, 
                CharSequence query, 
                boolean submit)

This method was deprecated in API level 26.0.0.
Use setQuery(CharSequence, boolean) directly.

Sets a query string in the text field and optionally submits the query as well.

Parameters
searchView View: The SearchView to operate on.

query CharSequence: the query string. This replaces any query text already present in the text field.

submit boolean: whether to submit the query right now or only update the contents of text field.

setQueryHint

added in version 22.0.0
void setQueryHint (View searchView, 
                CharSequence hint)

This method was deprecated in API level 26.0.0.
Use setQueryHint(CharSequence) directly.

Sets the hint text to display in the query text field. This overrides any hint specified in the SearchableInfo.

Parameters
searchView View: The SearchView to operate on.

hint CharSequence: the hint text to display

setQueryRefinementEnabled

added in version 22.0.0
void setQueryRefinementEnabled (View searchView, 
                boolean enable)

This method was deprecated in API level 26.0.0.
Use setQueryRefinementEnabled(boolean) directly.

Specifies if a query refinement button should be displayed alongside each suggestion or if it should depend on the flags set in the individual items retrieved from the suggestions provider. Clicking on the query refinement button will replace the text in the query text field with the text from the suggestion. This flag only takes effect if a SearchableInfo has been specified with setSearchableInfo(View, ComponentName) and not when using a custom adapter.

Parameters
searchView View: The SearchView to operate on.

enable boolean: true if all items should have a query refinement button, false if only those items that have a query refinement flag set should have the button.

See also:

setSearchableInfo

added in version 22.0.0
void setSearchableInfo (View searchView, 
                ComponentName searchableComponent)

This method was deprecated in API level 26.0.0.
Use setSearchableInfo(SearchableInfo) directly.

Sets the SearchableInfo for this SearchView. Properties in the SearchableInfo are used to display labels, hints, suggestions, create intents for launching search results screens and controlling other affordances such as a voice button.

Parameters
searchView View: The SearchView to operate on.

searchableComponent ComponentName: The application component whose SearchableInfo should be loaded and applied to the SearchView.

setSubmitButtonEnabled

added in version 22.0.0
void setSubmitButtonEnabled (View searchView, 
                boolean enabled)

This method was deprecated in API level 26.0.0.
Use setSubmitButtonEnabled(boolean) directly.

Enables showing a submit button when the query is non-empty. In cases where the SearchView is being used to filter the contents of the current activity and doesn't launch a separate results activity, then the submit button should be disabled.

Parameters
searchView View: The SearchView to operate on.

enabled boolean: true to show a submit button for submitting queries, false if a submit button is not required.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)