SearchView


class SearchView : LinearLayoutCompat, 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(context: Context)
SearchView(context: Context, attrs: AttributeSet?)
SearchView(context: Context, attrs: AttributeSet?, defStyleAttr: Int)

Public functions

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

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.

Unit

Called when this view is collapsed as an action view.

Unit

Called when this view is expanded as an action view.

Unit
onWindowFocusChanged(hasWindowFocus: Boolean)
Boolean
requestFocus(direction: Int, previouslyFocusedRect: Rect!)
Unit

Iconifies or expands the SearchView.

Unit

Sets the default or resting state of the search field.

Unit
setImeOptions(imeOptions: Int)

Sets the IME options on the query text field.

Unit
setInputType(inputType: Int)

Sets the input type on the query text field.

Unit
setMaxWidth(maxpixels: Int)

Makes the view at most this many pixels wide maxWidth

Unit

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

Unit

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

Unit

Sets a listener for user actions within the SearchView.

Unit

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

Unit

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

Unit
setQuery(query: CharSequence!, submit: Boolean)

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

Unit

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

Unit

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.

Unit

Sets the SearchableInfo for this SearchView.

Unit

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

Unit

You can set a custom adapter if you wish.

Protected functions

Unit
Unit
onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int)
Unit
onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int)
Unit

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

Unit
Parcelable!

Inherited Constants

From androidx.appcompat.widget.LinearLayoutCompat
const Int
const Int

Show a divider at the beginning of the group.

const Int

Show a divider at the end of the group.

const Int

Show dividers between each item in the group.

const Int

Don't show any dividers.

const Int
From android.view.View
const Int
const Int
const Int
const Int
const Int
const Int
const Property<View!, Float!>!
const Int
const String!
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE = "creditCardExpirationDate"
const String!
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY = "creditCardExpirationDay"
const String!
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH = "creditCardExpirationMonth"
const String!
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR = "creditCardExpirationYear"
const String!
const String!
AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE = "creditCardSecurityCode"
const String!
const String!
const String!
const String!
const String!
const String!
const String!
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const Int
const Int
const Int
const Int
const Int
const Int
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const Int
const Int
const Int
const Int
const Int
const Int
const Int
GONE = 8
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
KEEP_SCREEN_ON = 67108864
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
NO_ID = -1
const Int
const Int
const Int
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const Property<View!, Float!>!
const Property<View!, Float!>!
const Property<View!, Float!>!
const Property<View!, Float!>!
const Property<View!, Float!>!
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const IntArray<Int>!
const IntArray<Int>!
const Int
const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Property<View!, Float!>!
const Property<View!, Float!>!
const Property<View!, Float!>!
const String!
VIEW_LOG_TAG = "View"
const Int
const IntArray<Int>!
const Property<View!, Float!>!
const Property<View!, Float!>!
const Property<View!, Float!>!
From android.view.ViewGroup
const Int
const Int
const Int
const Int
const Int
const Int
const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

Inherited functions

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.

Unit
onDraw(canvas: Canvas)
Unit
Unit
Unit
setBaselineAligned(baselineAligned: Boolean)

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

Unit
Unit

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

Unit

Set padding displayed on both ends of dividers.

Unit

Describes how the child views are positioned.

Unit
setHorizontalGravity(horizontalGravity: Int)
Unit

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

Unit
setOrientation(orientation: Int)

Should the layout be a column or a row.

Unit
setShowDividers(showDividers: Int)

Set how dividers should be shown between items in this layout

Unit
setVerticalGravity(verticalGravity: Int)
Unit
setWeightSum(weightSum: Float)

Defines the desired weights sum.

Boolean
From android.view.View
Unit
Unit
Unit
ViewPropertyAnimator!
Unit
Unit
Boolean
Unit
Unit

This function is deprecated.

Unit
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Unit
Unit
Unit
Boolean
Unit
Unit
java-static Int
combineMeasuredStates(curState: Int, newState: Int)
Int
Int
Int
Unit
WindowInsets!
computeSystemWindowInsets(in: WindowInsets!, outLocalInsets: Rect!)
Int
Int
Int
AccessibilityNodeInfo!
Unit
Unit

This function is deprecated.

Boolean
Boolean
dispatchNestedFling(velocityX: Float, velocityY: Float, consumed: Boolean)
Boolean
dispatchNestedPreFling(velocityX: Float, velocityY: Float)
Boolean
dispatchNestedPrePerformAccessibilityAction(
    action: Int,
    arguments: Bundle!
)
Boolean
dispatchNestedPreScroll(
    dx: Int,
    dy: Int,
    consumed: IntArray!,
    offsetInWindow: IntArray!
)
Boolean
dispatchNestedScroll(
    dxConsumed: Int,
    dyConsumed: Int,
    dxUnconsumed: Int,
    dyUnconsumed: Int,
    offsetInWindow: IntArray!
)
Boolean
Unit
draw(canvas: Canvas!)
Unit
OnBackInvokedDispatcher!
T!
<T : View?> findViewById(id: Int)
T!
<T : View?> findViewWithTag(tag: Any!)
Boolean

This function is deprecated.

Unit
forceHasOverlappingRendering(hasOverlappingRendering: Boolean)
Unit
Unit
generateDisplayHash(
    hashAlgorithm: String!,
    bounds: Rect!,
    executor: Executor!,
    callback: DisplayHashResultCallback!
)
java-static Int
View.AccessibilityDelegate!
Int
AccessibilityNodeProvider!
CharSequence!
Int
Int
String!
String!
Float
Animation!
Matrix!
IBinder!
IntArray<Int>!
(Mutable)Map<Int!, Int!>!
Array<String!>!
AutofillId!
Int
AutofillValue!
Drawable!
BlendMode!
ColorStateList!
PorterDuff.Mode!
Int
Int
Float
Int
Float
Rect!
Boolean
getClipBounds(outRect: Rect!)
Boolean
ContentCaptureSession!
CharSequence!
Context!
ContextMenu.ContextMenuInfo!
Boolean
java-static Int
getDefaultSize(size: Int, measureSpec: Int)
Display!
IntArray<Int>!
Bitmap!

This function is deprecated.

Int

This function is deprecated.

Int

This function is deprecated.

Unit
getDrawingRect(outRect: Rect!)
Long
Float
Int
Boolean
Boolean
Int
ArrayList<View!>!
getFocusables(direction: Int)
Unit
Drawable!
Int
BlendMode!
ColorStateList!
PorterDuff.Mode!
Boolean
getGlobalVisibleRect(r: Rect!, globalOffset: Point!)
Handler!
Float
Float
Float
Float
Runnable!
Boolean
Int
Unit
getHitRect(outRect: Rect!)
Int
Int
Drawable!
Drawable!
Int
Int
Int
Int
Boolean
KeyEvent.DispatcherState!
Int
Int
Int
ViewGroup.LayoutParams!
Int
Float
Int
Boolean
Unit
Unit
Unit
Matrix!
Int
Int
Int
Int
Int
Int
Int
Int
Int
Int
Int
Int
Int
View.OnFocusChangeListener!
Int
ViewOutlineProvider!
Int
Int
ViewOverlay!
Int
Int
Int
Int
Int
Int
ViewParent!
ViewParent!
Float
Float
PointerIcon!
(Mutable)List<Rect!>!
Array<String!>!
Resources!
Boolean
Int
Float
Int
AttachedSurfaceControl!
View!
WindowInsets!
Float
Float
Float
Float
Float
Int
Int
Int
Int
Int
Int
Int
Int
Int
Int
CharSequence!
StateListAnimator!
Int
Int
(Mutable)List<Rect!>!
Int

This function is deprecated.

Any!
Int
Int
CharSequence!
Int
Float
Int
TouchDelegate!
ArrayList<View!>!
Float
String!
Float
Float
Float
Long
Int
Int
Drawable!
Drawable!
Int
ViewTranslationResponse!
ViewTreeObserver!
Int
Int
Int
WindowId!
WindowInsetsController!
Int

This function is deprecated.

IBinder!
Int
Unit
Float
Float
Float
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
java-static View!
inflate(context: Context!, resource: Int, root: ViewGroup!)
Unit
invalidate(dirty: Rect!)

This function is deprecated.

Unit
Unit
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean

This function is deprecated.

Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
View!
keyboardNavigationClusterSearch(currentCluster: View!, direction: Int)
Unit
measure(widthMeasureSpec: Int, heightMeasureSpec: Int)
java-static IntArray<Int>!
mergeDrawableStates(baseState: IntArray!, additionalState: IntArray!)
Unit
Unit
Unit
Unit
WindowInsets!
Unit
Boolean
Boolean
Unit
Unit
InputConnection!
Unit
onCreateViewTranslationRequest(
    supportedFormats: IntArray!,
    requestsCollector: Consumer<ViewTranslationRequest!>!
)
Unit
onCreateVirtualViewTranslationRequests(
    virtualIds: LongArray!,
    supportedFormats: IntArray!,
    requestsCollector: Consumer<ViewTranslationRequest!>!
)
Unit
Boolean
Unit
onDraw(canvas: Canvas!)
Unit
Unit
Boolean
Unit
Unit
Unit
onFocusChanged(
    gainFocus: Boolean,
    direction: Int,
    previouslyFocusedRect: Rect!
)
Boolean
Unit
Boolean
Unit
Unit
Boolean
onKeyDown(keyCode: Int, event: KeyEvent!)
Boolean
onKeyLongPress(keyCode: Int, event: KeyEvent!)
Boolean
onKeyMultiple(keyCode: Int, repeatCount: Int, event: KeyEvent!)
Boolean
onKeyPreIme(keyCode: Int, event: KeyEvent!)
Boolean
onKeyShortcut(keyCode: Int, event: KeyEvent!)
Boolean
onKeyUp(keyCode: Int, event: KeyEvent!)
Unit
onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int)
Unit
onOverScrolled(
    scrollX: Int,
    scrollY: Int,
    clampedX: Boolean,
    clampedY: Boolean
)
Unit
Unit
Unit
Unit
Unit
Unit
Unit
ContentInfo!
Unit
onRtlPropertiesChanged(layoutDirection: Int)
Unit
onScreenStateChanged(screenState: Int)
Unit
onScrollCaptureSearch(
    localVisibleRect: Rect!,
    windowOffset: Point!,
    targets: Consumer<ScrollCaptureTarget!>!
)
Unit
onScrollChanged(l: Int, t: Int, oldl: Int, oldt: Int)
Boolean
onSetAlpha(alpha: Int)
Unit
onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int)
Unit
Boolean
Boolean
Unit
Unit
Unit
Unit
onVisibilityChanged(changedView: View!, visibility: Int)
Unit

This function is deprecated.

Unit
Boolean
overScrollBy(
    deltaX: Int,
    deltaY: Int,
    scrollX: Int,
    scrollY: Int,
    scrollRangeX: Int,
    scrollRangeY: Int,
    maxOverScrollX: Int,
    maxOverScrollY: Int,
    isTouchEvent: Boolean
)
Boolean
performAccessibilityAction(action: Int, arguments: Bundle!)
Boolean
Boolean
Boolean
performHapticFeedback(feedbackConstant: Int)
Boolean
ContentInfo!
Unit
playSoundEffect(soundConstant: Int)
Boolean
post(action: Runnable!)
Boolean
postDelayed(action: Runnable!, delayMillis: Long)
Unit
Unit
postInvalidateDelayed(delayMilliseconds: Long)
Unit
Unit
Unit
postOnAnimationDelayed(action: Runnable!, delayMillis: Long)
Unit
Unit
Boolean
Unit
Unit
Unit
Unit
Unit

This function is deprecated.

Boolean
Unit
Unit
Boolean
Unit
T!
<T : View?> requireViewById(id: Int)
Unit
java-static Int
resolveSize(size: Int, measureSpec: Int)
java-static Int
resolveSizeAndState(size: Int, measureSpec: Int, childMeasuredState: Int)
Unit
Unit
saveAttributeDataForStyleable(
    context: Context!,
    styleable: IntArray!,
    attrs: AttributeSet!,
    t: TypedArray!,
    defStyleAttr: Int,
    defStyleRes: Int
)
Unit
Unit
scheduleDrawable(who: Drawable!, what: Runnable!, when: Long)
Unit
scrollBy(x: Int, y: Int)
Unit
scrollTo(x: Int, y: Int)
Unit
Unit
Unit
setAccessibilityDataSensitive(accessibilityDataSensitive: Int)
Unit
Unit
Unit
Unit
setAccessibilityPaneTitle(accessibilityPaneTitle: CharSequence!)
Unit
Unit
Unit
setActivated(activated: Boolean)
Unit
setAllowClickWhenDisabled(clickableWhenDisabled: Boolean)
Unit
Unit
Unit
setAlpha(alpha: Float)
Unit
setAnimation(animation: Animation!)
Unit
Unit
Unit
setAutofillHints(autofillHints: Array<String!>!)
Unit
Unit
setBackground(background: Drawable!)
Unit
Unit

This function is deprecated.

Unit
Unit
Unit
Unit
Unit
setBottom(bottom: Int)
Unit
Unit
setClickable(clickable: Boolean)
Unit
setClipBounds(clipBounds: Rect!)
Unit
setClipToOutline(clipToOutline: Boolean)
Unit
Unit
setContentDescription(contentDescription: CharSequence!)
Unit
setContextClickable(contextClickable: Boolean)
Unit
setDefaultFocusHighlightEnabled(defaultFocusHighlightEnabled: Boolean)
Unit

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit
Unit
setElevation(elevation: Float)
Unit
setEnabled(enabled: Boolean)
Unit
Unit
Unit
setFitsSystemWindows(fitSystemWindows: Boolean)
Unit
setFocusable(focusable: Boolean)
Unit
setFocusableInTouchMode(focusableInTouchMode: Boolean)
Unit
setFocusedByDefault(isFocusedByDefault: Boolean)
Unit
Unit
setForeground(foreground: Drawable!)
Unit
Unit
Unit
Unit
Unit
setHandwritingBoundsOffsets(
    offsetLeft: Float,
    offsetTop: Float,
    offsetRight: Float,
    offsetBottom: Float
)
Unit
Unit
setHapticFeedbackEnabled(hapticFeedbackEnabled: Boolean)
Unit
setHasTransientState(hasTransientState: Boolean)
Unit
setHorizontalFadingEdgeEnabled(horizontalFadingEdgeEnabled: Boolean)
Unit
setHorizontalScrollBarEnabled(horizontalScrollBarEnabled: Boolean)
Unit
Unit
Unit
setHovered(hovered: Boolean)
Unit
setId(id: Int)
Unit
Unit
Unit
Unit
setIsCredential(isCredential: Boolean)
Unit
setIsHandwritingDelegate(isHandwritingDelegate: Boolean)
Unit
setKeepScreenOn(keepScreenOn: Boolean)
Unit
Unit
Unit
Unit
setLayerType(layerType: Int, paint: Paint!)
Unit
setLayoutDirection(layoutDirection: Int)
Unit
Unit
setLeft(left: Int)
Unit
setLeftTopRightBottom(left: Int, top: Int, right: Int, bottom: Int)
Unit
setLongClickable(longClickable: Boolean)
Unit
setMeasuredDimension(measuredWidth: Int, measuredHeight: Int)
Unit
setMinimumHeight(minHeight: Int)
Unit
setMinimumWidth(minWidth: Int)
Unit
Unit
setNextClusterForwardId(nextClusterForwardId: Int)
Unit
setNextFocusDownId(nextFocusDownId: Int)
Unit
setNextFocusForwardId(nextFocusForwardId: Int)
Unit
setNextFocusLeftId(nextFocusLeftId: Int)
Unit
setNextFocusRightId(nextFocusRightId: Int)
Unit
setNextFocusUpId(nextFocusUpId: Int)
Unit
Unit
Unit
Unit
Unit
Unit
Unit
Unit
Unit
Unit
Unit
Unit
setOnReceiveContentListener(
    mimeTypes: Array<String!>!,
    listener: OnReceiveContentListener!
)
Unit
Unit

This function is deprecated.

Unit
Unit
Unit
Unit
Unit
setOverScrollMode(overScrollMode: Int)
Unit
setPadding(left: Int, top: Int, right: Int, bottom: Int)
Unit
setPaddingRelative(start: Int, top: Int, end: Int, bottom: Int)
Unit
setPivotX(pivotX: Float)
Unit
setPivotY(pivotY: Float)
Unit
setPointerIcon(pointerIcon: PointerIcon!)
Unit
setPreferKeepClear(preferKeepClear: Boolean)
Unit
Unit
setPressed(pressed: Boolean)
Unit
setRenderEffect(renderEffect: RenderEffect!)
Unit
setRevealOnFocusHint(revealOnFocus: Boolean)
Unit
setRight(right: Int)
Unit
setRotation(rotation: Float)
Unit
setRotationX(rotationX: Float)
Unit
setRotationY(rotationY: Float)
Unit
Unit
Unit
setScaleX(scaleX: Float)
Unit
setScaleY(scaleY: Float)
Unit
setScreenReaderFocusable(screenReaderFocusable: Boolean)
Unit
setScrollBarDefaultDelayBeforeFade(
    scrollBarDefaultDelayBeforeFade: Int
)
Unit
setScrollBarFadeDuration(scrollBarFadeDuration: Int)
Unit
setScrollBarSize(scrollBarSize: Int)
Unit
Unit
Unit
Unit
setScrollContainer(isScrollContainer: Boolean)
Unit
setScrollIndicators(indicators: Int)
Unit
setScrollX(value: Int)
Unit
setScrollY(value: Int)
Unit
Unit
setSelected(selected: Boolean)
Unit
setSoundEffectsEnabled(soundEffectsEnabled: Boolean)
Unit
setStateDescription(stateDescription: CharSequence!)
Unit
Unit
Unit

This function is deprecated.

Unit
setTag(tag: Any!)
Unit
setTextAlignment(textAlignment: Int)
Unit
setTextDirection(textDirection: Int)
Unit
Unit
setTop(top: Int)
Unit
Unit
Unit
setTransitionName(transitionName: String!)
Unit
Unit
setTranslationX(translationX: Float)
Unit
setTranslationY(translationY: Float)
Unit
setTranslationZ(translationZ: Float)
Unit
setVerticalFadingEdgeEnabled(verticalFadingEdgeEnabled: Boolean)
Unit
setVerticalScrollBarEnabled(verticalScrollBarEnabled: Boolean)
Unit
Unit
Unit
Unit
Unit
setVisibility(visibility: Int)
Unit
setWillNotCacheDrawing(willNotCacheDrawing: Boolean)

This function is deprecated.

Unit
setWillNotDraw(willNotDraw: Boolean)
Unit
setX(x: Float)
Unit
setY(y: Float)
Unit
setZ(z: Float)
Boolean
ActionMode!
Unit
Boolean
startDrag(
    data: ClipData!,
    shadowBuilder: View.DragShadowBuilder!,
    myLocalState: Any!,
    flags: Int
)

This function is deprecated.

Boolean
startDragAndDrop(
    data: ClipData!,
    shadowBuilder: View.DragShadowBuilder!,
    myLocalState: Any!,
    flags: Int
)
Boolean
Unit
String!
Unit
Unit
Unit
Unit
Boolean
Boolean

This function is deprecated.

Boolean
From android.view.ViewGroup
Unit
Unit
addExtraDataToAccessibilityNodeInfo(
    info: AccessibilityNodeInfo!,
    extraDataKey: String!,
    arguments: Bundle!
)
Unit
addFocusables(views: ArrayList<View!>!, direction: Int, focusableMode: Int)
Unit
addKeyboardNavigationClusters(
    views: (Mutable)Collection<View!>!,
    direction: Int
)
Boolean
Unit
Unit
addView(child: View!)
Boolean
addViewInLayout(child: View!, index: Int, params: ViewGroup.LayoutParams!)
Unit
attachLayoutAnimationParameters(
    child: View!,
    params: ViewGroup.LayoutParams!,
    index: Int,
    count: Int
)
Unit
attachViewToParent(child: View!, index: Int, params: ViewGroup.LayoutParams!)
Unit
Boolean
Boolean
Unit
Unit
childHasTransientStateChanged(
    child: View!,
    childHasTransientState: Boolean
)
Unit
Unit
Unit
Unit
debug(depth: Int)
Unit
Unit
Unit
detachViewsFromParent(start: Int, count: Int)
WindowInsets!
Boolean
Unit
Unit
dispatchCreateViewTranslationRequest(
    viewIds: (Mutable)Map<AutofillId!, LongArray!>!,
    supportedFormats: IntArray!,
    capability: TranslationCapability!,
    requests: (Mutable)List<ViewTranslationRequest!>!
)
Unit
Boolean
Unit
dispatchDraw(canvas: Canvas!)
Unit
Unit
Unit
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Unit
Unit
Unit
Unit
Unit
Unit
dispatchScrollCaptureSearch(
    localVisibleRect: Rect!,
    windowOffset: Point!,
    targets: Consumer<ScrollCaptureTarget!>!
)
Unit
Unit
Unit
Unit
Unit

This function is deprecated.

Unit
Boolean
Boolean
Boolean
dispatchUnhandledMove(focused: View!, direction: Int)
Unit
dispatchVisibilityChanged(changedView: View!, visibility: Int)
Unit
Unit
Unit
WindowInsets!
dispatchWindowInsetsAnimationProgress(
    insets: WindowInsets!,
    runningAnimations: (Mutable)List<WindowInsetsAnimation!>!
)
WindowInsetsAnimation.Bounds!
Unit

This function is deprecated.

Unit
Boolean
drawChild(canvas: Canvas!, child: View!, drawingTime: Long)
Unit
Unit
View!
OnBackInvokedDispatcher!
Unit
findViewsWithText(
    outViews: ArrayList<View!>!,
    text: CharSequence!,
    flags: Int
)
View!
focusSearch(focused: View!, direction: Int)
Unit
Boolean
ViewGroup.LayoutParams!
ViewGroup.LayoutParams!
CharSequence!
View!
getChildAt(index: Int)
Int
Int
getChildDrawingOrder(childCount: Int, drawingPosition: Int)
java-static Int
getChildMeasureSpec(spec: Int, padding: Int, childDimension: Int)
Boolean
Boolean
getChildVisibleRect(child: View!, r: Rect!, offset: Point!)
Boolean
Boolean
Int
View!
LayoutAnimationController!
Animation.AnimationListener!
Int
LayoutTransition!
Int
ViewGroupOverlay!
Int

This function is deprecated.

Boolean
Boolean
Boolean
Int
indexOfChild(child: View!)
Unit
invalidateChild(child: View!, dirty: Rect!)

This function is deprecated.

ViewParent!
invalidateChildInParent(location: IntArray!, dirty: Rect!)

This function is deprecated.

Boolean

This function is deprecated.

Boolean

This function is deprecated.

Boolean
Boolean

This function is deprecated.

Boolean
Boolean
Boolean
Unit
Unit
layout(l: Int, t: Int, r: Int, b: Int)
Unit
measureChild(
    child: View!,
    parentWidthMeasureSpec: Int,
    parentHeightMeasureSpec: Int
)
Unit
measureChildWithMargins(
    child: View!,
    parentWidthMeasureSpec: Int,
    widthUsed: Int,
    parentHeightMeasureSpec: Int,
    heightUsed: Int
)
Unit
measureChildren(widthMeasureSpec: Int, heightMeasureSpec: Int)
Unit
notifySubtreeAccessibilityStateChanged(
    child: View!,
    source: View!,
    changeType: Int
)
Unit
offsetDescendantRectToMyCoords(descendant: View!, rect: Rect!)
Unit
offsetRectIntoDescendantCoords(descendant: View!, rect: Rect!)
Unit
IntArray<Int>!
Unit
onDescendantInvalidated(child: View!, target: View!)
Boolean
Boolean
abstract Unit
onLayout(p: Boolean, p1: Int, p2: Int, p3: Int, p4: Int)
Boolean
onNestedFling(
    target: View!,
    velocityX: Float,
    velocityY: Float,
    consumed: Boolean
)
Boolean
onNestedPreFling(target: View!, velocityX: Float, velocityY: Float)
Boolean
onNestedPrePerformAccessibilityAction(
    target: View!,
    action: Int,
    args: Bundle!
)
Unit
onNestedPreScroll(target: View!, dx: Int, dy: Int, consumed: IntArray!)
Unit
onNestedScroll(
    target: View!,
    dxConsumed: Int,
    dyConsumed: Int,
    dxUnconsumed: Int,
    dyUnconsumed: Int
)
Unit
onNestedScrollAccepted(child: View!, target: View!, axes: Int)
Boolean
onRequestFocusInDescendants(direction: Int, previouslyFocusedRect: Rect!)
Boolean
PointerIcon!
onResolvePointerIcon(event: MotionEvent!, pointerIndex: Int)
Boolean
onStartNestedScroll(child: View!, target: View!, nestedScrollAxes: Int)
Unit
Unit
onViewAdded(child: View!)
Unit
Unit
Unit
Unit
Unit
removeDetachedView(child: View!, animate: Boolean)
Unit
removeView(view: View!)
Unit
removeViewAt(index: Int)
Unit
Unit
removeViews(start: Int, count: Int)
Unit
removeViewsInLayout(start: Int, count: Int)
Unit
requestChildFocus(child: View!, focused: View!)
Boolean
requestChildRectangleOnScreen(
    child: View!,
    rectangle: Rect!,
    immediate: Boolean
)
Unit
Boolean
Unit
Boolean
Unit
Unit
Unit

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit
Unit

This function is deprecated.

Unit
setClipChildren(clipChildren: Boolean)
Unit
setClipToPadding(clipToPadding: Boolean)
Unit
Unit
Unit
Unit
setLayoutMode(layoutMode: Int)
Unit
Unit
Unit
Unit
setPersistentDrawingCache(drawingCacheToKeep: Int)

This function is deprecated.

Unit
Unit
setTouchscreenBlocksFocus(touchscreenBlocksFocus: Boolean)
Unit
setTransitionGroup(isTransitionGroup: Boolean)
Unit
Boolean
Boolean
showContextMenuForChild(originalView: View!)
ActionMode!
startActionModeForChild(
    originalView: View!,
    callback: ActionMode.Callback!
)
Unit
Unit
Unit
Unit

Public constructors

SearchView

Added in 1.1.0
SearchView(context: Context)

SearchView

Added in 1.1.0
SearchView(context: Context, attrs: AttributeSet?)

SearchView

Added in 1.1.0
SearchView(context: Context, attrs: AttributeSet?, defStyleAttr: Int)

Public functions

clearFocus

fun clearFocus(): Unit

getImeOptions

Added in 1.1.0
@Attribute(value = "android:imeOptions")
fun getImeOptions(): Int

Returns the IME options set on the query text field.

Returns
Int

the ime options

getInputType

Added in 1.1.0
fun getInputType(): Int

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")
fun getMaxWidth(): Int

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
fun getQuery(): CharSequence!

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")
fun getQueryHint(): CharSequence?

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
CharSequence?

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

getSuggestionsAdapter

Added in 1.1.0
fun getSuggestionsAdapter(): CursorAdapter!

Returns the adapter used for suggestions, if any.

Returns
CursorAdapter!

the suggestions adapter

isIconfiedByDefault

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

Returns the default iconified state of the search field.

isIconified

Added in 1.1.0
fun isIconified(): Boolean

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
fun isQueryRefinementEnabled(): Boolean

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
fun isSubmitButtonEnabled(): Boolean

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
fun onActionViewCollapsed(): Unit

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

onActionViewExpanded

Added in 1.7.0
fun onActionViewExpanded(): Unit

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

onWindowFocusChanged

fun onWindowFocusChanged(hasWindowFocus: Boolean): Unit

requestFocus

fun requestFocus(direction: Int, previouslyFocusedRect: Rect!): Boolean

setIconified

Added in 1.1.0
fun setIconified(iconify: Boolean): Unit

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
iconify: Boolean

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

setIconifiedByDefault

Added in 1.1.0
fun setIconifiedByDefault(iconified: Boolean): Unit

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
iconified: Boolean

whether the search field should be iconified by default iconifiedByDefault

setImeOptions

Added in 1.1.0
fun setImeOptions(imeOptions: Int): Unit

Sets the IME options on the query text field.

Parameters
imeOptions: Int

the options to set on the query text field imeOptions

See also
setImeOptions

setInputType

Added in 1.1.0
fun setInputType(inputType: Int): Unit

Sets the input type on the query text field.

Parameters
inputType: Int

the input type to set on the query text field inputType

See also
setInputType

setMaxWidth

Added in 1.1.0
fun setMaxWidth(maxpixels: Int): Unit

Makes the view at most this many pixels wide maxWidth

setOnCloseListener

Added in 1.1.0
fun setOnCloseListener(listener: SearchView.OnCloseListener!): Unit

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

Parameters
listener: SearchView.OnCloseListener!

the listener to call when the user closes the SearchView.

setOnQueryTextFocusChangeListener

Added in 1.1.0
fun setOnQueryTextFocusChangeListener(listener: View.OnFocusChangeListener!): Unit

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

Parameters
listener: View.OnFocusChangeListener!

the listener to inform of focus changes.

setOnQueryTextListener

Added in 1.1.0
fun setOnQueryTextListener(listener: SearchView.OnQueryTextListener!): Unit

Sets a listener for user actions within the SearchView.

Parameters
listener: SearchView.OnQueryTextListener!

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
fun setOnSearchClickListener(listener: View.OnClickListener!): Unit

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
listener: View.OnClickListener!

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

setOnSuggestionListener

Added in 1.1.0
fun setOnSuggestionListener(listener: SearchView.OnSuggestionListener!): Unit

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

Parameters
listener: SearchView.OnSuggestionListener!

the listener to inform of suggestion selection events.

setQuery

Added in 1.1.0
fun setQuery(query: CharSequence!, submit: Boolean): Unit

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

Parameters
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 1.1.0
fun setQueryHint(hint: CharSequence?): Unit

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
hint: CharSequence?

the hint text to display or null to clear queryHint

setQueryRefinementEnabled

Added in 1.1.0
fun setQueryRefinementEnabled(enable: Boolean): Unit

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

setSearchableInfo

Added in 1.1.0
fun setSearchableInfo(searchable: SearchableInfo!): Unit

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

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

setSubmitButtonEnabled

Added in 1.1.0
fun setSubmitButtonEnabled(enabled: Boolean): Unit

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
enabled: Boolean

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

setSuggestionsAdapter

Added in 1.1.0
fun setSuggestionsAdapter(adapter: CursorAdapter!): Unit

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 functions

onDetachedFromWindow

protected fun onDetachedFromWindow(): Unit

onLayout

protected fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int): Unit

onMeasure

protected fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int): Unit

onQueryRefine

Added in 1.5.0
protected fun onQueryRefine(queryText: CharSequence?): Unit

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
queryText: CharSequence?

the proposed query refinement

onRestoreInstanceState

protected fun onRestoreInstanceState(state: Parcelable!): Unit

onSaveInstanceState

protected fun onSaveInstanceState(): Parcelable!