public final class SearchViewCompat extends Object
SearchView
introduced after API level 4 in a backwards compatible fashion.Modifier and Type | Class and Description |
---|---|
static interface |
SearchViewCompat.OnCloseListener
Callback for closing the query UI.
|
static class |
SearchViewCompat.OnCloseListenerCompat
Deprecated.
Use
SearchViewCompat.OnCloseListener instead. |
static interface |
SearchViewCompat.OnQueryTextListener
Callbacks for changes to the query text.
|
static class |
SearchViewCompat.OnQueryTextListenerCompat
Deprecated.
Use
SearchViewCompat.OnQueryTextListener instead. |
Modifier and Type | Method and Description |
---|---|
static CharSequence |
getQuery(View searchView)
Returns the query string currently in the text field.
|
static boolean |
isIconified(View searchView)
Returns the current iconified state of the SearchView.
|
static boolean |
isQueryRefinementEnabled(View searchView)
Returns whether query refinement is enabled for all items or only specific ones.
|
static boolean |
isSubmitButtonEnabled(View searchView)
Returns whether the submit button is enabled when necessary or never displayed.
|
static View |
newSearchView(Context context)
Creates a new SearchView.
|
static void |
setIconified(View searchView,
boolean iconify)
Iconifies or expands the SearchView.
|
static void |
setImeOptions(View searchView,
int imeOptions)
Sets the IME options on the query text field.
|
static void |
setInputType(View searchView,
int inputType)
Sets the input type on the query text field.
|
static void |
setMaxWidth(View searchView,
int maxpixels)
Makes the view at most this many pixels wide
|
static void |
setOnCloseListener(View searchView,
SearchViewCompat.OnCloseListener listener)
Sets a listener to inform when the user closes the SearchView.
|
static void |
setOnQueryTextListener(View searchView,
SearchViewCompat.OnQueryTextListener listener)
Sets a listener for user actions within the SearchView.
|
static void |
setQuery(View searchView,
CharSequence query,
boolean submit)
Sets a query string in the text field and optionally submits the query as well.
|
static void |
setQueryHint(View searchView,
CharSequence hint)
Sets the hint text to display in the query text field.
|
static void |
setQueryRefinementEnabled(View searchView,
boolean enable)
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.
|
static void |
setSearchableInfo(View searchView,
ComponentName searchableComponent)
Sets the SearchableInfo for this SearchView.
|
static void |
setSubmitButtonEnabled(View searchView,
boolean enabled)
Enables showing a submit button when the query is non-empty.
|
public static View newSearchView(Context context)
context
- The Context the view is running in.public static void setSearchableInfo(View searchView, ComponentName searchableComponent)
searchView
- The SearchView to operate on.searchableComponent
- The application component whose
SearchableInfo
should be loaded and applied to
the SearchView.public static void setImeOptions(View searchView, int imeOptions)
Build.VERSION_CODES.ICE_CREAM_SANDWICH
platforms.searchView
- The SearchView to operate on.imeOptions
- the options to set on the query text fieldTextView.setImeOptions(int)
public static void setInputType(View searchView, int inputType)
Build.VERSION_CODES.ICE_CREAM_SANDWICH
platforms.searchView
- The SearchView to operate on.inputType
- the input type to set on the query text fieldTextView.setInputType(int)
public static void setOnQueryTextListener(View searchView, SearchViewCompat.OnQueryTextListener listener)
searchView
- The SearchView in which to register the listener.listener
- the listener object that receives callbacks when the user performs
actions in the SearchView such as clicking on buttons or typing a query.public static void setOnCloseListener(View searchView, SearchViewCompat.OnCloseListener listener)
searchView
- The SearchView in which to register the listener.listener
- the listener to call when the user closes the SearchView.public static CharSequence getQuery(View searchView)
searchView
- The SearchView to operate on.public static void setQuery(View searchView, CharSequence query, boolean submit)
searchView
- The SearchView to operate on.query
- the query string. This replaces any query text already present in the
text field.submit
- whether to submit the query right now or only update the contents of
text field.public static void setQueryHint(View searchView, CharSequence hint)
searchView
- The SearchView to operate on.hint
- the hint text to displaypublic static void setIconified(View searchView, boolean iconify)
searchView
- The SearchView to operate on.iconify
- a true value will collapse the SearchView to an icon, while a false will
expand it.public static boolean isIconified(View searchView)
searchView
- The SearchView to operate on.public static void setSubmitButtonEnabled(View searchView, boolean enabled)
searchView
- The SearchView to operate on.enabled
- true to show a submit button for submitting queries, false if a submit
button is not required.public static boolean isSubmitButtonEnabled(View searchView)
searchView
- The SearchView to operate on.public static void setQueryRefinementEnabled(View searchView, boolean enable)
setSearchableInfo(View, ComponentName)
and not when using a custom adapter.searchView
- The SearchView to operate on.enable
- 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.SearchManager.SUGGEST_COLUMN_FLAGS
,
SearchManager.FLAG_QUERY_REFINEMENT
public static boolean isQueryRefinementEnabled(View searchView)
searchView
- The SearchView to operate on.public static void setMaxWidth(View searchView, int maxpixels)
searchView
- The SearchView to operate on.