SearchBar

open class SearchBar : RelativeLayout
kotlin.Any
   ↳ android.view.View
   ↳ android.view.ViewGroup
   ↳ android.widget.RelativeLayout
   ↳ androidx.leanback.widget.SearchBar

A search widget containing a search orb and a text entry view.

Note: When SpeechRecognitionCallback is not used, i.e. using SpeechRecognizer, your application will need to declare android.permission.RECORD_AUDIO in manifest file. If your application target >= 23 and the device is running >= 23, it needs implement SearchBarPermissionListener where requests runtime permission.

Summary

Nested classes
abstract

Interface for receiving notification of search query changes.

abstract

Interface that handles runtime permissions requests.

Public constructors
<init>(context: Context!)

<init>(context: Context!, attrs: AttributeSet!)

<init>(context: Context!, attrs: AttributeSet!, defStyle: Int)

Public methods
open Unit

Sets the badge drawable showing inside the search bar.

open CharSequence!

Returns the current search bar hint text.

open Unit

Sets background color of listening state search orb.

open Drawable!

Returns the badge drawable

open Unit

Updates the completion list shown by the IME

open Unit

Updates the completion list shown by the IME

open Unit

Sets the speech recognizer to be used when doing voice search.

open Unit

open Boolean

Returns true if is not running Recognizer, false otherwise.

open Unit

Sets listener that handles runtime permission requests.

open Unit

open Unit

Sets the search query

open String!

Returns the current title

open Unit

Sets background color of not-listening state search orb.

open Unit
setTitle(title: String!)

Sets the title text used in the hint shown in the search bar.

open Unit

Sets the speech recognition callback.

open Unit

Stops the speech recognition, if already started.

open Unit

Sets a listener for when the term search changes

Protected methods
open Unit

open Unit

open Unit

Public constructors

<init>

SearchBar(context: Context!)

<init>

SearchBar(context: Context!, attrs: AttributeSet!)

<init>

SearchBar(context: Context!, attrs: AttributeSet!, defStyle: Int)

Public methods

setBadgeDrawable

open fun setBadgeDrawable(drawable: Drawable!): Unit

Sets the badge drawable showing inside the search bar.

Parameters
drawable Drawable!: The drawable to be used in the search bar.

getHint

open fun getHint(): CharSequence!

Returns the current search bar hint text.

setSearchAffordanceColorsInListening

open fun setSearchAffordanceColorsInListening(colors: SearchOrbView.Colors!): Unit

Sets background color of listening state search orb.

Parameters
colors SearchOrbView.Colors!: SearchOrbView.Colors.

getBadgeDrawable

open fun getBadgeDrawable(): Drawable!

Returns the badge drawable

displayCompletions

open fun displayCompletions(completions: MutableList<String!>!): Unit

Updates the completion list shown by the IME

Parameters
completions MutableList<String!>!: list of completions shown in the IME, can be null or empty to clear them

displayCompletions

open fun displayCompletions(completions: Array<CompletionInfo!>!): Unit

Updates the completion list shown by the IME

Parameters
completions Array<CompletionInfo!>!: list of completions shown in the IME, can be null or empty to clear them

setSpeechRecognizer

open fun setSpeechRecognizer(recognizer: SpeechRecognizer!): Unit

Sets the speech recognizer to be used when doing voice search. The Activity/Fragment is in charge of creating and destroying the recognizer with its own lifecycle.

Parameters
recognizer SpeechRecognizer!: a SpeechRecognizer

setNextFocusDownId

open fun setNextFocusDownId(viewId: Int): Unit

isRecognizing

open fun isRecognizing(): Boolean

Returns true if is not running Recognizer, false otherwise.

Return
Boolean: True if is not running Recognizer, false otherwise.

setPermissionListener

open fun setPermissionListener(listener: SearchBar.SearchBarPermissionListener!): Unit

Sets listener that handles runtime permission requests.

Parameters
listener SearchBar.SearchBarPermissionListener!: Listener that handles runtime permission requests.

startRecognition

open fun startRecognition(): Unit

setSearchQuery

open fun setSearchQuery(query: String!): Unit

Sets the search query

Parameters
query String!: the search query to use

getTitle

open fun getTitle(): String!

Returns the current title

setSearchAffordanceColors

open fun setSearchAffordanceColors(colors: SearchOrbView.Colors!): Unit

Sets background color of not-listening state search orb.

Parameters
colors SearchOrbView.Colors!: SearchOrbView.Colors.

setTitle

open fun setTitle(title: String!): Unit

Sets the title text used in the hint shown in the search bar.

Parameters
title String!: The hint to use.

setSpeechRecognitionCallback

open fun setSpeechRecognitionCallback(request: SpeechRecognitionCallback!): Unit

Sets the speech recognition callback.

stopRecognition

open fun stopRecognition(): Unit

Stops the speech recognition, if already started.

setSearchBarListener

open fun setSearchBarListener(listener: SearchBar.SearchBarListener!): Unit

Sets a listener for when the term search changes

Parameters
listener SearchBar.SearchBarListener!:

Protected methods

onAttachedToWindow

protected open fun onAttachedToWindow(): Unit

onFinishInflate

protected open fun onFinishInflate(): Unit

onDetachedFromWindow

protected open fun onDetachedFromWindow(): Unit