belongs to Maven artifact com.android.support:appcompat-v7:28.0.0-alpha1
SearchView
public
class
SearchView
extends LinearLayoutCompat
implements
CollapsibleActionView
java.lang.Object | ||||
↳ | android.view.View | |||
↳ | android.view.ViewGroup | |||
↳ | android.support.v7.widget.LinearLayoutCompat | |||
↳ | android.support.v7.widget.SearchView |
A widget that provides a user interface for the user to enter a search query and submit a request to a search provider. Shows a list of query suggestions or results, if available, and allows the user to pick a suggestion or result to launch into.
Note: This class is included in the support library for compatibility
with API level 7 and higher. If you're developing your app for API level 11 and higher
only, you should instead use the framework SearchView
class.
When the SearchView is used in an ActionBar
as an action view, it's collapsed by default, so you must provide an icon for the action.
If you want the search field to always be visible, then call
setIconifiedByDefault(false)
.
Developer Guides
For information about using SearchView
, read the
Search API guide.
Additional information about action views is also available in the <Action Bar API guide
See also:
Summary
Nested classes | |
---|---|
interface |
SearchView.OnCloseListener
|
interface |
SearchView.OnQueryTextListener
Callbacks for changes to the query text. |
interface |
SearchView.OnSuggestionListener
Callback interface for selection events on suggestions. |
XML attributes | |
---|---|
SearchView_android_imeOptions |
|
SearchView_android_inputType |
|
SearchView_android_maxWidth |
|
SearchView_iconifiedByDefault |
|
SearchView_queryHint |
Inherited constants |
---|
![]()
android.support.v7.widget.LinearLayoutCompat
|
![]()
android.view.ViewGroup
|
![]()
android.view.View
|
Inherited fields |
---|
![]()
android.view.View
|
Public constructors | |
---|---|
SearchView(Context context)
|
|
SearchView(Context context, AttributeSet attrs)
|
|
SearchView(Context context, AttributeSet attrs, int defStyleAttr)
|
Public methods | |
---|---|
void
|
clearFocus()
|
int
|
getImeOptions()
Returns the IME options set on the query text field. |
int
|
getInputType()
Returns the input type set on the query text field. |
int
|
getMaxWidth()
Gets the specified maximum width in pixels, if set. |
CharSequence
|
getQuery()
Returns the query string currently in the text field. |
CharSequence
|
getQueryHint()
Returns the hint text that will be displayed in the query text field. |
CursorAdapter
|
getSuggestionsAdapter()
Returns the adapter used for suggestions, if any. |
boolean
|
isIconfiedByDefault()
Returns the default iconified state of the search field. |
boolean
|
isIconified()
Returns the current iconified state of the SearchView. |
boolean
|
isQueryRefinementEnabled()
Returns whether query refinement is enabled for all items or only specific ones. |
boolean
|
isSubmitButtonEnabled()
Returns whether the submit button is enabled when necessary or never displayed. |
void
|
onActionViewCollapsed()
Called when this view is collapsed as an action view. |
void
|
onActionViewExpanded()
Called when this view is expanded as an action view. |
void
|
onWindowFocusChanged(boolean hasWindowFocus)
|
boolean
|
requestFocus(int direction, Rect previouslyFocusedRect)
|
void
|
setIconified(boolean iconify)
Iconifies or expands the SearchView. |
void
|
setIconifiedByDefault(boolean iconified)
Sets the default or resting state of the search field. |
void
|
setImeOptions(int imeOptions)
Sets the IME options on the query text field. |
void
|
setInputType(int inputType)
Sets the input type on the query text field. |
void
|
setMaxWidth(int maxpixels)
Makes the view at most this many pixels wide |
void
|
setOnCloseListener(SearchView.OnCloseListener listener)
Sets a listener to inform when the user closes the SearchView. |
void
|
setOnQueryTextFocusChangeListener(View.OnFocusChangeListener listener)
Sets a listener to inform when the focus of the query text field changes. |
void
|
setOnQueryTextListener(SearchView.OnQueryTextListener listener)
Sets a listener for user actions within the SearchView. |
void
|
setOnSearchClickListener(View.OnClickListener listener)
Sets a listener to inform when the search button is pressed. |
void
|
setOnSuggestionListener(SearchView.OnSuggestionListener listener)
Sets a listener to inform when a suggestion is focused or clicked. |
void
|
setQuery(CharSequence query, boolean submit)
Sets a query string in the text field and optionally submits the query as well. |
void
|
setQueryHint(CharSequence hint)
Sets the hint text to display in the query text field. |
void
|