Register now for Android Dev Summit 2019!

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

Updates the completion list shown by the IME

open Unit

Updates the completion list shown by the IME

open Drawable!

Returns the badge drawable

open CharSequence!

Returns the current search bar hint text.

open String!

Returns the current title

open Boolean

Returns true if is not running Recognizer, false otherwise.

open Unit

Sets the badge drawable showing inside the search bar.

open Unit

open Unit

Sets listener that handles runtime permission requests.

open Unit

Sets background color of not-listening state search orb.

open Unit

Sets background color of listening state search orb.

open Unit

Sets a listener for when the term search changes

open Unit

Sets the search query

open Unit

Sets the speech recognition callback.

open Unit

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

open Unit
setTitle(title: String!)

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

open Unit

open Unit

Stops the speech recognition, if already started.

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

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

getBadgeDrawable

open fun getBadgeDrawable(): Drawable!

Returns the badge drawable

getHint

open fun getHint(): CharSequence!

Returns the current search bar hint text.

getTitle

open fun getTitle(): String!

Returns the current title

isRecognizing

open fun isRecognizing(): Boolean

Returns true if is not running Recognizer, false otherwise.

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

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.

setNextFocusDownId

open fun setNextFocusDownId(viewId: Int): Unit

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.

setSearchAffordanceColors

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

Sets background color of not-listening state search orb.

Parameters
colors SearchOrbView.Colors!: SearchOrbView.Colors.

setSearchAffordanceColorsInListening

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

Sets background color of listening state search orb.

Parameters
colors SearchOrbView.Colors!: SearchOrbView.Colors.

setSearchBarListener

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

Sets a listener for when the term search changes

Parameters
listener SearchBar.SearchBarListener!:

setSearchQuery

open fun setSearchQuery(query: String!): Unit

Sets the search query

Parameters
query String!: the search query to use

setSpeechRecognitionCallback

open fun setSpeechRecognitionCallback(request: SpeechRecognitionCallback!): Unit

Deprecated: Launching voice recognition activity is no longer supported. App should declare android.permission.RECORD_AUDIO in AndroidManifest file. See details in androidx.leanback.app.SearchSupportFragment.

Sets the speech recognition callback.

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

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.

startRecognition

open fun startRecognition(): Unit

stopRecognition

open fun stopRecognition(): Unit

Stops the speech recognition, if already started.

Protected methods

onAttachedToWindow

protected open fun onAttachedToWindow(): Unit

onDetachedFromWindow

protected open fun onDetachedFromWindow(): Unit

onFinishInflate

protected open fun onFinishInflate(): Unit