SearchView

public class SearchView extends LinearLayoutCompat implements CollapsibleActionView


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.

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

Summary

Nested types

Callbacks for changes to the query text.

Callback interface for selection events on suggestions.

Public constructors

SearchView(
    @NonNull Context context,
    @Nullable AttributeSet attrs,
    int defStyleAttr
)

Public methods

void
int
@Attribute(value = "android:imeOptions")
getImeOptions()

Returns the IME options set on the query text field.

int

Returns the input type set on the query text field.

int
@Attribute(value = "android:maxWidth")
getMaxWidth()

Gets the specified maximum width in pixels, if set.

CharSequence

Returns the query string currently in the text field.

@Nullable CharSequence
@Attribute(value = "androidx.appcompat:queryHint")
getQueryHint()

Returns the hint text that will be displayed in the query text field.

CursorAdapter

Returns the adapter used for suggestions, if any.

boolean
@Attribute(value = "androidx.appcompat:iconifiedByDefault")
isIconfiedByDefault()

Returns the default iconified state of the search field.

boolean

Returns the current iconified state of the SearchView.

boolean

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

boolean

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

void

Called when this view is collapsed as an action view.

void

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 maxWidth

void

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

void

Sets a listener to inform when the focus of the query text field changes.

void

Sets a listener for user actions within the SearchView.

void

Sets a listener to inform when the search button is pressed.

void

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

Sets the hint text to display in the query text field.

void
setQueryRefinementEnabled(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.

void

Sets the SearchableInfo for this SearchView.

void
setSubmitButtonEnabled(boolean enabled)

Enables showing a submit button when the query is non-empty.

void

You can set a custom adapter if you wish.

Protected methods

void
void
onLayout(boolean changed, int left, int top, int right, int bottom)
void
onMeasure(int widthMeasureSpec, int heightMeasureSpec)
void

Called when a query refinement has been proposed, e.g. when the user clicks on a suggestion provided by a SuggestionsAdapter.

void
Parcelable

Inherited Constants

From androidx.appcompat.widget.LinearLayoutCompat
static final int
static final int

Show a divider at the beginning of the group.

static final int

Show a divider at the end of the group.

static final int

Show dividers between each item in the group.

static final int

Don't show any dividers.

static final int
From android.view.View
static final int
static final int
static final int
static final int
static final int
static final int
static final Property<ViewFloat>
static final int
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE = "creditCardExpirationDate"
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY = "creditCardExpirationDay"
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH = "creditCardExpirationMonth"
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR = "creditCardExpirationYear"
static final String
static final String
AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE = "creditCardSecurityCode"
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int
static final int
static final int
static final int
static final int
static final int
static final int[]
static final int[]
static final int[]
static final int[]
static final int
static final int
static final int
static final int
static final int
static final int
static final int
GONE = 8
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
KEEP_SCREEN_ON = 67108864
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
NO_ID = -1
static final int
static final int
static final int
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int[]
static final int[]
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final String
VIEW_LOG_TAG = "View"
static final int
static final int[]
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
From android.view.ViewGroup
static final int
static final int
static final int
static final int
static final int
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

Inherited methods

From androidx.appcompat.widget.LinearLayoutCompat
boolean
LinearLayoutCompat.LayoutParams

Returns a set of layout parameters with a width of MATCH_PARENT and a height of WRAP_CONTENT when the layout's orientation is VERTICAL.

LinearLayoutCompat.LayoutParams
LinearLayoutCompat.LayoutParams
int
int
@Attribute(value = "android:baselineAlignedChildIndex")
getBaselineAlignedChildIndex()
Drawable
@Attribute(value = "androidx.appcompat:divider")
getDividerDrawable()
int
@Attribute(value = "androidx.appcompat:dividerPadding")
getDividerPadding()

Get the padding size used to inset dividers in pixels

@GravityInt int
@Attribute(value = "android:gravity")
getGravity()

Returns the current gravity.

int
@Attribute(value = "android:orientation", intMapping = [@Attribute.IntMap(name = "horizontal", value = 0), @Attribute.IntMap(name = "vertical", value = 1)])
getOrientation()

Returns the current orientation.

int
@Attribute(value = "androidx.appcompat:showDividers", intMapping = [@Attribute.IntMap(name = "none", value = 0), @Attribute.IntMap(name = "beginning", value = 1, mask = 1), @Attribute.IntMap(name = "middle", value = 2, mask = 2), @Attribute.IntMap(name = "end", value = 4, mask = 4)])
getShowDividers()
float
@Attribute(value = "android:weightSum")
getWeightSum()

Returns the desired weights sum.

boolean
@Attribute(value = "android:baselineAligned")
isBaselineAligned()

Indicates whether widgets contained within this layout are aligned on their baseline or not.

boolean
@Attribute(value = "androidx.appcompat:measureWithLargestChild")
isMeasureWithLargestChildEnabled()

When true, all children with a weight will be considered having the minimum size of the largest child.

void
void
void
void
setBaselineAligned(boolean baselineAligned)

Defines whether widgets contained in this layout are baseline-aligned or not.

void
void

Set a drawable to be used as a divider between items.

void
setDividerPadding(int padding)

Set padding displayed on both ends of dividers.

void
setGravity(@GravityInt int gravity)

Describes how the child views are positioned.

void
setHorizontalGravity(int horizontalGravity)
void

When set to true, all children with a weight will be considered having the minimum size of the largest child.

void
setOrientation(int orientation)

Should the layout be a column or a row.

void
setShowDividers(int showDividers)

Set how dividers should be shown between items in this layout

void
setVerticalGravity(int verticalGravity)
void
setWeightSum(float weightSum)

Defines the desired weights sum.

boolean
From android.view.View
void
void
void
ViewPropertyAnimator
void
void
boolean
void
void

This method is deprecated.

void
boolean
boolean
boolean
boolean
boolean
canScrollHorizontally(int direction)
boolean
canScrollVertically(int direction)
final void
void
final void
boolean
void
void
static int
combineMeasuredStates(int curState, int newState)
int
int
int
void
WindowInsets
int
int
int
AccessibilityNodeInfo
void
void

This method is deprecated.

boolean
boolean
dispatchNestedFling(float velocityX, float velocityY, boolean consumed)
boolean
dispatchNestedPreFling(float velocityX, float velocityY)
boolean
dispatchNestedPrePerformAccessibilityAction(
    int action,
    Bundle arguments
)
boolean
dispatchNestedPreScroll(
    int dx,
    int dy,
    int[] consumed,
    int[] offsetInWindow
)
boolean
dispatchNestedScroll(
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed,
    int[] offsetInWindow
)
boolean
void
draw(Canvas canvas)
void
drawableHotspotChanged(float x, float y)
final OnBackInvokedDispatcher
final T
<T extends View> findViewById(int id)
final T
<T extends View> findViewWithTag(Object tag)
boolean

This method is deprecated.

void
forceHasOverlappingRendering(boolean hasOverlappingRendering)
void
void
generateDisplayHash(
    String hashAlgorithm,
    Rect bounds,
    Executor executor,
    DisplayHashResultCallback callback
)
static int
View.AccessibilityDelegate
int
AccessibilityNodeProvider
CharSequence
int
int
String
String
float
Animation
Matrix
IBinder
int[]
Map<IntegerInteger>
String[]
final AutofillId
int
AutofillValue
Drawable
BlendMode
ColorStateList
PorterDuff.Mode
int
final int
float
int
float
Rect
boolean
final boolean
final ContentCaptureSession
CharSequence
final Context
ContextMenu.ContextMenuInfo
final boolean
static int
getDefaultSize(int size, int measureSpec)
Display
final int[]
Bitmap

This method is deprecated.

int

This method is deprecated.

int

This method is deprecated.

void
long
float
int
boolean
boolean
int
ArrayList<View>
getFocusables(int direction)
void
Drawable
int
BlendMode
ColorStateList
PorterDuff.Mode
boolean
getGlobalVisibleRect(Rect r, Point globalOffset)
Handler
float
float
float
float
Runnable
final boolean
final int
void
getHitRect(Rect outRect)
int
int
Drawable
Drawable
int
int
int
int
boolean
KeyEvent.DispatcherState
int
int
int
ViewGroup.LayoutParams
final int
float
int
final boolean
void
getLocationInSurface(int[] location)
void
getLocationInWindow(int[] outLocation)
void
getLocationOnScreen(int[] outLocation)
Matrix
final int
final int
final int
final int
final int
int
int
int
int
int
int
int
int
View.OnFocusChangeListener
int
ViewOutlineProvider
int
int
ViewOverlay
int
int
int
int
int
int
final ViewParent
ViewParent
float
float
PointerIcon
final List<Rect>
String[]
Resources
final boolean
final int
float
int
AttachedSurfaceControl
View
WindowInsets
float
float
float
float
float
int
int
int
int
int
int
final int
final int
int
int
final CharSequence
StateListAnimator
int
int
List<Rect>
int

This method is deprecated.

Object
int
int
CharSequence
final int
float
int
TouchDelegate
ArrayList<View>
float
String
float
float
float
long
int
int
Drawable
Drawable
int
ViewTranslationResponse
ViewTreeObserver
int
final int
int
WindowId
WindowInsetsController
int

This method is deprecated.

IBinder
int
void
float
float
float
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
static View
inflate(Context context, int resource, ViewGroup root)
void

This method is deprecated.

void
void
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean

This method is deprecated.

boolean
boolean
final boolean
final boolean
boolean
final boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
final boolean
final boolean
boolean
boolean
boolean
final boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
final boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
final boolean
boolean
boolean
final boolean
boolean
boolean
boolean
boolean
boolean
View
keyboardNavigationClusterSearch(View currentCluster, int direction)
final void
measure(int widthMeasureSpec, int heightMeasureSpec)
static int[]
mergeDrawableStates(int[] baseState, int[] additionalState)
void
offsetLeftAndRight(int offset)
void
offsetTopAndBottom(int offset)
void
void
WindowInsets
void
boolean
boolean
void
void
InputConnection
void
onCreateViewTranslationRequest(
    int[] supportedFormats,
    Consumer<ViewTranslationRequest> requestsCollector
)
void
onCreateVirtualViewTranslationRequests(
    long[] virtualIds,
    int[] supportedFormats,
    Consumer<ViewTranslationRequest> requestsCollector
)
void
onDisplayHint(int hint)
boolean
void
onDraw(Canvas canvas)
void
final void
boolean
void
void
void
onFocusChanged(
    boolean gainFocus,
    int direction,
    Rect previouslyFocusedRect
)
boolean
void
onHoverChanged(boolean hovered)
boolean
void
void
boolean
onKeyDown(int keyCode, KeyEvent event)
boolean
onKeyLongPress(int keyCode, KeyEvent event)
boolean
onKeyMultiple(int keyCode, int repeatCount, KeyEvent event)
boolean
onKeyPreIme(int keyCode, KeyEvent event)
boolean
onKeyShortcut(int keyCode, KeyEvent event)
boolean
onKeyUp(int keyCode, KeyEvent event)
void
onMeasure(int widthMeasureSpec, int heightMeasureSpec)
void
onOverScrolled(
    int scrollX,
    int scrollY,
    boolean clampedX,
    boolean clampedY
)
void
onPointerCaptureChange(boolean hasCapture)
void
void
onProvideAutofillStructure(ViewStructure structure, int flags)
void
void
void
void
ContentInfo
void
onRtlPropertiesChanged(int layoutDirection)
void
onScreenStateChanged(int screenState)
void
onScrollCaptureSearch(
    Rect localVisibleRect,
    Point windowOffset,
    Consumer<ScrollCaptureTarget> targets
)
void
onScrollChanged(int l, int t, int oldl, int oldt)
boolean
onSetAlpha(int alpha)
void
onSizeChanged(int w, int h, int oldw, int oldh)
void
boolean
boolean
void
void
void
onVisibilityAggregated(boolean isVisible)
void
onVisibilityChanged(View changedView, int visibility)
void

This method is deprecated.

void
onWindowVisibilityChanged(int visibility)
boolean
overScrollBy(
    int deltaX,
    int deltaY,
    int scrollX,
    int scrollY,
    int scrollRangeX,
    int scrollRangeY,
    int maxOverScrollX,
    int maxOverScrollY,
    boolean isTouchEvent
)
boolean
performAccessibilityAction(int action, Bundle arguments)
boolean
boolean
performContextClick(float x, float y)
boolean
performHapticFeedback(int feedbackConstant)
boolean
ContentInfo
void
playSoundEffect(int soundConstant)
boolean
post(Runnable action)
boolean
postDelayed(Runnable action, long delayMillis)
void
void
postInvalidateDelayed(long delayMilliseconds)
void
void
void
postOnAnimationDelayed(Runnable action, long delayMillis)
void
void
boolean
void
void
void
void
void

This method is deprecated.

final boolean
void
void
boolean
final void
final T
<T extends View> requireViewById(int id)
void
static int
resolveSize(int size, int measureSpec)
static int
resolveSizeAndState(int size, int measureSpec, int childMeasuredState)
void
final void
saveAttributeDataForStyleable(
    Context context,
    int[] styleable,
    AttributeSet attrs,
    TypedArray t,
    int defStyleAttr,
    int defStyleRes
)
void
void
scheduleDrawable(Drawable who, Runnable what, long when)
void
scrollBy(int x, int y)
void
scrollTo(int x, int y)
void
sendAccessibilityEvent(int eventType)
void
void
setAccessibilityDataSensitive(int accessibilityDataSensitive)
void
void
setAccessibilityHeading(boolean isHeading)
void
void
setAccessibilityPaneTitle(CharSequence accessibilityPaneTitle)
void
void
void
setActivated(boolean activated)
void
setAllowClickWhenDisabled(boolean clickableWhenDisabled)
void
void
void
setAlpha(float alpha)
void
void
void
setAutoHandwritingEnabled(boolean enabled)
void
setAutofillHints(String[] autofillHints)
void
void
setBackground(Drawable background)
void
setBackgroundColor(int color)
void

This method is deprecated.

void
void
void
void
final void
setBottom(int bottom)
void
setCameraDistance(float distance)
void
setClickable(boolean clickable)
void
setClipBounds(Rect clipBounds)
void
setClipToOutline(boolean clipToOutline)
void
void
setContentDescription(CharSequence contentDescription)
void
setContextClickable(boolean contextClickable)
void
setDefaultFocusHighlightEnabled(boolean defaultFocusHighlightEnabled)
void

This method is deprecated.

void
setDrawingCacheEnabled(boolean enabled)

This method is deprecated.

void

This method is deprecated.

void
void
setElevation(float elevation)
void
setEnabled(boolean enabled)
void
setFadingEdgeLength(int length)
void
void
setFitsSystemWindows(boolean fitSystemWindows)
void
setFocusable(boolean focusable)
void
setFocusableInTouchMode(boolean focusableInTouchMode)
void
setFocusedByDefault(boolean isFocusedByDefault)
void
setForceDarkAllowed(boolean allow)
void
setForeground(Drawable foreground)
void
setForegroundGravity(int gravity)
void
void
void
void
setHandwritingBoundsOffsets(
    float offsetLeft,
    float offsetTop,
    float offsetRight,
    float offsetBottom
)
void
void
setHapticFeedbackEnabled(boolean hapticFeedbackEnabled)
void
setHasTransientState(boolean hasTransientState)
void
setHorizontalFadingEdgeEnabled(boolean horizontalFadingEdgeEnabled)
void
setHorizontalScrollBarEnabled(boolean horizontalScrollBarEnabled)
void
void
void
setHovered(boolean hovered)
void
setId(int id)
void
void
void
void
setIsCredential(boolean isCredential)
void
setIsHandwritingDelegate(boolean isHandwritingDelegate)
void
setKeepScreenOn(boolean keepScreenOn)
void
setKeyboardNavigationCluster(boolean isCluster)
void
setLabelFor(int id)
void
void
setLayerType(int layerType, Paint paint)
void
setLayoutDirection(int layoutDirection)
void
final void
setLeft(int left)
final void
setLeftTopRightBottom(int left, int top, int right, int bottom)
void
setLongClickable(boolean longClickable)
final void
setMeasuredDimension(int measuredWidth, int measuredHeight)
void
setMinimumHeight(int minHeight)
void
setMinimumWidth(int minWidth)
void
setNestedScrollingEnabled(boolean enabled)
void
setNextClusterForwardId(int nextClusterForwardId)
void
setNextFocusDownId(int nextFocusDownId)
void
setNextFocusForwardId(int nextFocusForwardId)
void
setNextFocusLeftId(int nextFocusLeftId)
void
setNextFocusRightId(int nextFocusRightId)
void
setNextFocusUpId(int nextFocusUpId)
void
void
void
void
void
void
void
void
void
void
void
void
setOnReceiveContentListener(
    String[] mimeTypes,
    OnReceiveContentListener listener
)
void
void

This method is deprecated.

void
void
void
void
void
setOverScrollMode(int overScrollMode)
void
setPadding(int left, int top, int right, int bottom)
void
setPaddingRelative(int start, int top, int end, int bottom)
void
setPivotX(float pivotX)
void
setPivotY(float pivotY)
void
final void
setPreferKeepClear(boolean preferKeepClear)
final void
void
setPressed(boolean pressed)
void
final void
setRevealOnFocusHint(boolean revealOnFocus)
final void
setRight(int right)
void
setRotation(float rotation)
void
setRotationX(float rotationX)
void
setRotationY(float rotationY)
void
setSaveEnabled(boolean enabled)
void
setSaveFromParentEnabled(boolean enabled)
void
setScaleX(float scaleX)
void
setScaleY(float scaleY)
void
setScreenReaderFocusable(boolean screenReaderFocusable)
void
setScrollBarDefaultDelayBeforeFade(
    int scrollBarDefaultDelayBeforeFade
)
void
setScrollBarFadeDuration(int scrollBarFadeDuration)
void
setScrollBarSize(int scrollBarSize)
void
setScrollBarStyle(int style)
final void
void
void
setScrollContainer(boolean isScrollContainer)
void
setScrollIndicators(int indicators)
void
setScrollX(int value)
void
setScrollY(int value)
void
setScrollbarFadingEnabled(boolean fadeScrollbars)
void
setSelected(boolean selected)
void
setSoundEffectsEnabled(boolean soundEffectsEnabled)
void
void
void
void
setSystemUiVisibility(int visibility)

This method is deprecated.

void
void
setTextAlignment(int textAlignment)
void
setTextDirection(int textDirection)
void
final void
setTop(int top)
void
void
setTransitionAlpha(float alpha)
final void
setTransitionName(String transitionName)
void
setTransitionVisibility(int visibility)
void
setTranslationX(float translationX)
void
setTranslationY(float translationY)
void
setTranslationZ(float translationZ)
void
setVerticalFadingEdgeEnabled(boolean verticalFadingEdgeEnabled)
void
setVerticalScrollBarEnabled(boolean verticalScrollBarEnabled)
void
void
void
void
void
setVisibility(int visibility)
void
setWillNotCacheDrawing(boolean willNotCacheDrawing)

This method is deprecated.

void
setWillNotDraw(boolean willNotDraw)
void
setX(float x)
void
setY(float y)
void
setZ(float z)
boolean
ActionMode
void
final boolean
startDrag(
    ClipData data,
    View.DragShadowBuilder shadowBuilder,
    Object myLocalState,
    int flags
)

This method is deprecated.

final boolean
startDragAndDrop(
    ClipData data,
    View.DragShadowBuilder shadowBuilder,
    Object myLocalState,
    int flags
)
boolean
void
String
void
void
void
final void
boolean
boolean

This method is deprecated.

boolean
From android.view.ViewGroup
void
void
addExtraDataToAccessibilityNodeInfo(
    AccessibilityNodeInfo info,
    String extraDataKey,
    Bundle arguments
)
void
addFocusables(ArrayList<View> views, int direction, int focusableMode)
void
boolean
void
void
addView(View child)
boolean
addViewInLayout(View child, int index, ViewGroup.LayoutParams params)
void
attachLayoutAnimationParameters(
    View child,
    ViewGroup.LayoutParams params,
    int index,
    int count
)
void
attachViewToParent(View child, int index, ViewGroup.LayoutParams params)
void
boolean
boolean
void
void
childHasTransientStateChanged(
    View child,
    boolean childHasTransientState
)
void
void
void
void
debug(int depth)
void
void
void
detachViewsFromParent(int start, int count)
WindowInsets
boolean
void
void
dispatchCreateViewTranslationRequest(
    Map<AutofillId, long[]> viewIds,
    int[] supportedFormats,
    TranslationCapability capability,
    List<ViewTranslationRequest> requests
)
void
boolean
void
void
dispatchDrawableHotspotChanged(float x, float y)
void
void
boolean
boolean
boolean
boolean
boolean
boolean
void
dispatchPointerCaptureChanged(boolean hasCapture)
void
void
void
void
void
dispatchScrollCaptureSearch(
    Rect localVisibleRect,
    Point windowOffset,
    Consumer<ScrollCaptureTarget> targets
)
void
dispatchSetActivated(boolean activated)
void
dispatchSetPressed(boolean pressed)
void
dispatchSetSelected(boolean selected)
void
void

This method is deprecated.

void
boolean
boolean
boolean
dispatchUnhandledMove(View focused, int direction)
void
dispatchVisibilityChanged(View changedView, int visibility)
void
dispatchWindowFocusChanged(boolean hasFocus)
void
void
WindowInsets
WindowInsetsAnimation.Bounds
void

This method is deprecated.

void
boolean
drawChild(Canvas canvas, View child, long drawingTime)
void
void
View
OnBackInvokedDispatcher
void
findViewsWithText(
    ArrayList<View> outViews,
    CharSequence text,
    int flags
)
View
focusSearch(View focused, int direction)
void
boolean
ViewGroup.LayoutParams
ViewGroup.LayoutParams
CharSequence
View
getChildAt(int index)
int
int
getChildDrawingOrder(int childCount, int drawingPosition)
static int
getChildMeasureSpec(int spec, int padding, int childDimension)
boolean
boolean
getChildVisibleRect(View child, Rect r, Point offset)
boolean
boolean
int
View
LayoutAnimationController
Animation.AnimationListener
int
LayoutTransition
int
ViewGroupOverlay
int

This method is deprecated.

boolean
boolean
boolean
int
final void
invalidateChild(View child, Rect dirty)

This method is deprecated.

ViewParent
invalidateChildInParent(int[] location, Rect dirty)

This method is deprecated.

boolean

This method is deprecated.

boolean

This method is deprecated.

boolean
boolean

This method is deprecated.

boolean
boolean
boolean
void
final void
layout(int l, int t, int r, int b)
void
measureChild(
    View child,
    int parentWidthMeasureSpec,
    int parentHeightMeasureSpec
)
void
measureChildWithMargins(
    View child,
    int parentWidthMeasureSpec,
    int widthUsed,
    int parentHeightMeasureSpec,
    int heightUsed
)
void
measureChildren(int widthMeasureSpec, int heightMeasureSpec)
void
notifySubtreeAccessibilityStateChanged(
    View child,
    View source,
    int changeType
)
final void
final void
void
int[]
onCreateDrawableState(int extraSpace)
void
boolean
boolean
abstract void
onLayout(boolean p, int p1, int p2, int p3, int p4)
boolean
onNestedFling(
    View target,
    float velocityX,
    float velocityY,
    boolean consumed
)
boolean
onNestedPreFling(View target, float velocityX, float velocityY)
boolean
onNestedPrePerformAccessibilityAction(
    View target,
    int action,
    Bundle args
)
void
onNestedPreScroll(View target, int dx, int dy, int[] consumed)
void
onNestedScroll(
    View target,
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed
)
void
onNestedScrollAccepted(View child, View target, int axes)
boolean
onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect)
boolean
PointerIcon
onResolvePointerIcon(MotionEvent event, int pointerIndex)
boolean
onStartNestedScroll(View child, View target, int nestedScrollAxes)
void
void
void
void
void
void
void
removeDetachedView(View child, boolean animate)
void
void
removeViewAt(int index)
void
void
removeViews(int start, int count)
void
removeViewsInLayout(int start, int count)
void
requestChildFocus(View child, View focused)
boolean
requestChildRectangleOnScreen(
    View child,
    Rect rectangle,
    boolean immediate
)
void
requestDisallowInterceptTouchEvent(boolean disallowIntercept)
boolean
void
boolean
void
void
setAddStatesFromChildren(boolean addsStates)
void

This method is deprecated.

void
setAnimationCacheEnabled(boolean enabled)

This method is deprecated.

void

This method is deprecated.

void
void

This method is deprecated.

void
setClipChildren(boolean clipChildren)
void
setClipToPadding(boolean clipToPadding)
void
setDescendantFocusability(int focusability)
void
void
void
setLayoutMode(int layoutMode)
void
void
void
void
setPersistentDrawingCache(int drawingCacheToKeep)

This method is deprecated.

void
void
setTouchscreenBlocksFocus(boolean touchscreenBlocksFocus)
void
setTransitionGroup(boolean isTransitionGroup)
void
boolean
boolean
ActionMode
startActionModeForChild(
    View originalView,
    ActionMode.Callback callback
)
void
void
void
suppressLayout(boolean suppress)
void

Public constructors

SearchView

Added in 1.1.0
public SearchView(@NonNull Context context)

SearchView

Added in 1.1.0
public SearchView(@NonNull Context context, @Nullable AttributeSet attrs)

SearchView

Added in 1.1.0
public SearchView(
    @NonNull Context context,
    @Nullable AttributeSet attrs,
    int defStyleAttr
)

Public methods

clearFocus

public void clearFocus()

getImeOptions

Added in 1.1.0
@Attribute(value = "android:imeOptions")
public int getImeOptions()

Returns the IME options set on the query text field.

Returns
int

the ime options

getInputType

Added in 1.1.0
public int getInputType()

Returns the input type set on the query text field.

Returns
int

the input type inputType

getMaxWidth

Added in 1.1.0
@Attribute(value = "android:maxWidth")
public int getMaxWidth()

Gets the specified maximum width in pixels, if set. Returns zero if no maximum width was specified.

Returns
int

the maximum width of the view maxWidth

getQuery

Added in 1.1.0
public CharSequence getQuery()

Returns the query string currently in the text field.

Returns
CharSequence

the query string

getQueryHint

Added in 1.1.0
@Attribute(value = "androidx.appcompat:queryHint")
public @Nullable CharSequence getQueryHint()

Returns the hint text that will be displayed in the query text field.

The displayed query hint is chosen in the following order:

  1. Non-null value set with setQueryHint
  2. Value specified in XML using app:queryHint
  3. Valid string resource ID exposed by the SearchableInfo via getHintId
  4. Default hint provided by the theme against which the view was inflated
Returns
@Nullable CharSequence

the displayed query hint text, or null if none set queryHint

getSuggestionsAdapter

Added in 1.1.0
public CursorAdapter getSuggestionsAdapter()

Returns the adapter used for suggestions, if any.

Returns
CursorAdapter

the suggestions adapter

isIconfiedByDefault

Added in 1.1.0
@Attribute(value = "androidx.appcompat:iconifiedByDefault")
public boolean isIconfiedByDefault()

Returns the default iconified state of the search field.

Returns
boolean

iconifiedByDefault

isIconified

Added in 1.1.0
public boolean isIconified()

Returns the current iconified state of the SearchView.

Returns
boolean

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

isQueryRefinementEnabled

Added in 1.1.0
public boolean isQueryRefinementEnabled()

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

Returns
boolean

true if enabled for all items, false otherwise.

isSubmitButtonEnabled

Added in 1.1.0
public boolean isSubmitButtonEnabled()

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

Returns
boolean

whether the submit button is enabled automatically when necessary

onActionViewCollapsed

Added in 1.7.0-alpha03
public void onActionViewCollapsed()

Called when this view is collapsed as an action view. See android.view.MenuItem#collapseActionView().

onActionViewExpanded

Added in 1.7.0-alpha03
public void onActionViewExpanded()

Called when this view is expanded as an action view. See android.view.MenuItem#expandActionView().

onWindowFocusChanged

public void onWindowFocusChanged(boolean hasWindowFocus)

requestFocus

public boolean requestFocus(int direction, Rect previouslyFocusedRect)

setIconified

Added in 1.1.0
public void setIconified(boolean iconify)

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. 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
boolean iconify

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

setIconifiedByDefault

Added in 1.1.0
public void setIconifiedByDefault(boolean iconified)

Sets the default or resting state of the search field. If true, a single search icon is shown by default and expands to show the text field and other buttons when pressed. Also, if the default state is iconified, then it collapses to that state when the close button is pressed. Changes to this property will take effect immediately.

The default value is true.

Parameters
boolean iconified

whether the search field should be iconified by default iconifiedByDefault

setImeOptions

Added in 1.1.0
public void setImeOptions(int imeOptions)

Sets the IME options on the query text field.

Parameters
int imeOptions

the options to set on the query text field imeOptions

See also
setImeOptions

setInputType

Added in 1.1.0
public void setInputType(int inputType)

Sets the input type on the query text field.

Parameters
int inputType

the input type to set on the query text field inputType

See also
setInputType

setMaxWidth

Added in 1.1.0
public void setMaxWidth(int maxpixels)

Makes the view at most this many pixels wide maxWidth

setOnCloseListener

Added in 1.1.0
public void setOnCloseListener(SearchView.OnCloseListener listener)

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

Parameters
SearchView.OnCloseListener listener

the listener to call when the user closes the SearchView.

setOnQueryTextFocusChangeListener

Added in 1.1.0
public void setOnQueryTextFocusChangeListener(View.OnFocusChangeListener listener)

Sets a listener to inform when the focus of the query text field changes.

Parameters
View.OnFocusChangeListener listener

the listener to inform of focus changes.

setOnQueryTextListener

Added in 1.1.0
public void setOnQueryTextListener(SearchView.OnQueryTextListener listener)

Sets a listener for user actions within the SearchView.

Parameters
SearchView.OnQueryTextListener listener

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

setOnSearchClickListener

Added in 1.1.0
public void setOnSearchClickListener(View.OnClickListener listener)

Sets a listener to inform when the search button is pressed. This is only relevant when the text field is not visible by default. Calling setIconified(false) can also cause this listener to be informed.

Parameters
View.OnClickListener listener

the listener to inform when the search button is clicked or the text field is programmatically de-iconified.

setOnSuggestionListener

Added in 1.1.0
public void setOnSuggestionListener(SearchView.OnSuggestionListener listener)

Sets a listener to inform when a suggestion is focused or clicked.

Parameters
SearchView.OnSuggestionListener listener

the listener to inform of suggestion selection events.

setQuery

Added in 1.1.0
public void setQuery(CharSequence query, boolean submit)

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

Parameters
CharSequence query

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

boolean submit

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

setQueryHint

Added in 1.1.0
public void setQueryHint(@Nullable CharSequence hint)

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

This value may be specified as an empty string to prevent any query hint from being displayed.

Parameters
@Nullable CharSequence hint

the hint text to display or null to clear queryHint

setQueryRefinementEnabled

Added in 1.1.0
public void setQueryRefinementEnabled(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. 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 and not when using a custom adapter.

Parameters
boolean 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.

setSearchableInfo

Added in 1.1.0
public void setSearchableInfo(SearchableInfo searchable)

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

a SearchableInfo can be retrieved from the SearchManager, for a specific activity or a global search provider.

setSubmitButtonEnabled

Added in 1.1.0
public void setSubmitButtonEnabled(boolean enabled)

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

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

setSuggestionsAdapter

Added in 1.1.0
public void setSuggestionsAdapter(CursorAdapter adapter)

You can set a custom adapter if you wish. Otherwise the default adapter is used to display the suggestions from the suggestions provider associated with the SearchableInfo.

Protected methods

onDetachedFromWindow

protected void onDetachedFromWindow()

onLayout

protected void onLayout(boolean changed, int left, int top, int right, int bottom)

onMeasure

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

onQueryRefine

Added in 1.5.0
protected void onQueryRefine(@Nullable CharSequence queryText)

Called when a query refinement has been proposed, e.g. when the user clicks on a suggestion provided by a SuggestionsAdapter.

By default, this method sets the text in the query box without updating the suggestions.

Parameters
@Nullable CharSequence queryText

the proposed query refinement

onRestoreInstanceState

protected void onRestoreInstanceState(Parcelable state)

onSaveInstanceState

protected Parcelable onSaveInstanceState()