Skip to content

Most visited

Recently visited

navigation

SearchBar

public class SearchBar
extends RelativeLayout

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.RelativeLayout
         ↳ android.support.v17.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 SearchBar.SearchBarPermissionListener where requests runtime permission.

Summary

Nested classes

interface SearchBar.SearchBarListener

Interface for receiving notification of search query changes. 

interface SearchBar.SearchBarPermissionListener

Interface that handles runtime permissions requests. 

Inherited XML attributes

From class android.widget.RelativeLayout
From class android.view.ViewGroup
From class android.view.View

Inherited constants

From class android.widget.RelativeLayout
From class android.view.ViewGroup
From class android.view.View

Inherited fields

From class android.view.View

Public constructors

SearchBar(Context context)
SearchBar(Context context, AttributeSet attrs)
SearchBar(Context context, AttributeSet attrs, int defStyle)

Public methods

void displayCompletions(CompletionInfo[] completions)

Updates the completion list shown by the IME

void displayCompletions(List<String> completions)

Updates the completion list shown by the IME

Drawable getBadgeDrawable()

Returns the badge drawable

CharSequence getHint()

Returns the current search bar hint text.

String getTitle()

Returns the current title

boolean isRecognizing()

Returns true if is not running Recognizer, false otherwise.

void setBadgeDrawable(Drawable drawable)

Sets the badge drawable showing inside the search bar.

void setNextFocusDownId(int viewId)

Sets the id of the view to use when the next focus is FOCUS_DOWN.

void setPermissionListener(SearchBar.SearchBarPermissionListener listener)

Sets listener that handles runtime permission requests.

void setSearchAffordanceColors(SearchOrbView.Colors colors)

Sets background color of not-listening state search orb.

void setSearchAffordanceColorsInListening(SearchOrbView.Colors colors)

Sets background color of listening state search orb.

void setSearchBarListener(SearchBar.SearchBarListener listener)

Sets a listener for when the term search changes

void setSearchQuery(String query)

Sets the search query

void setSpeechRecognitionCallback(SpeechRecognitionCallback request)

Sets the speech recognition callback.

void setSpeechRecognizer(SpeechRecognizer recognizer)

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

void setTitle(String title)

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

void startRecognition()
void stopRecognition()

Stops the speech recognition, if already started.

Protected methods

void onAttachedToWindow()

This is called when the view is attached to a window.

void onDetachedFromWindow()

This is called when the view is detached from a window.

void onFinishInflate()

Finalize inflating a view from XML.

Inherited methods

From class android.widget.RelativeLayout
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.view.ViewParent
From interface android.view.ViewManager
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource

Public constructors

SearchBar

added in version 22.0.0
SearchBar (Context context)

Parameters
context Context

SearchBar

added in version 22.0.0
SearchBar (Context context, 
                AttributeSet attrs)

Parameters
context Context
attrs AttributeSet

SearchBar

added in version 22.0.0
SearchBar (Context context, 
                AttributeSet attrs, 
                int defStyle)

Parameters
context Context
attrs AttributeSet
defStyle int

Public methods

displayCompletions

added in version 23.1.0
void displayCompletions (CompletionInfo[] completions)

Updates the completion list shown by the IME

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

displayCompletions

added in version 22.0.0
void displayCompletions (List<String> completions)

Updates the completion list shown by the IME

Parameters
completions List: list of completions shown in the IME, can be null or empty to clear them

getBadgeDrawable

added in version 22.0.0
Drawable getBadgeDrawable ()

Returns the badge drawable

Returns
Drawable

getHint

added in version 22.0.0
CharSequence getHint ()

Returns the current search bar hint text.

Returns
CharSequence

getTitle

added in version 22.0.0
String getTitle ()

Returns the current title

Returns
String

isRecognizing

added in version 24.0.0
boolean isRecognizing ()

Returns true if is not running Recognizer, false otherwise.

Returns
boolean True if is not running Recognizer, false otherwise.

setBadgeDrawable

added in version 22.0.0
void setBadgeDrawable (Drawable drawable)

Sets the badge drawable showing inside the search bar.

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

setNextFocusDownId

void setNextFocusDownId (int viewId)

Sets the id of the view to use when the next focus is FOCUS_DOWN.

Parameters
viewId int: The next focus ID, or NO_ID if the framework should decide automatically.

setPermissionListener

added in version 24.0.0
void setPermissionListener (SearchBar.SearchBarPermissionListener listener)

Sets listener that handles runtime permission requests.

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

setSearchAffordanceColors

added in version 25.1.0
void setSearchAffordanceColors (SearchOrbView.Colors colors)

Sets background color of not-listening state search orb.

Parameters
colors SearchOrbView.Colors: SearchOrbView.Colors.

setSearchAffordanceColorsInListening

added in version 25.1.0
void setSearchAffordanceColorsInListening (SearchOrbView.Colors colors)

Sets background color of listening state search orb.

Parameters
colors SearchOrbView.Colors: SearchOrbView.Colors.

setSearchBarListener

added in version 22.0.0
void setSearchBarListener (SearchBar.SearchBarListener listener)

Sets a listener for when the term search changes

setSearchQuery

added in version 22.0.0
void setSearchQuery (String query)

Sets the search query

Parameters
query String: the search query to use

setSpeechRecognitionCallback

added in version 22.0.0
void setSpeechRecognitionCallback (SpeechRecognitionCallback request)

Sets the speech recognition callback.

Parameters
request SpeechRecognitionCallback

setSpeechRecognizer

added in version 22.0.0
void setSpeechRecognizer (SpeechRecognizer recognizer)

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

added in version 22.0.0
void setTitle (String title)

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

Parameters
title String: The hint to use.

startRecognition

added in version 22.0.0
void startRecognition ()

stopRecognition

added in version 22.0.0
void stopRecognition ()

Stops the speech recognition, if already started.

Protected methods

onAttachedToWindow

void onAttachedToWindow ()

This is called when the view is attached to a window. At this point it has a Surface and will start drawing. Note that this function is guaranteed to be called before onDraw(android.graphics.Canvas), however it may be called any time before the first onDraw -- including before or after onMeasure(int, int).

onDetachedFromWindow

void onDetachedFromWindow ()

This is called when the view is detached from a window. At this point it no longer has a surface for drawing.

onFinishInflate

void onFinishInflate ()

Finalize inflating a view from XML. This is called as the last phase of inflation, after all child views have been added.

Even if the subclass overrides onFinishInflate, they should always be sure to call the super method, so that we get called.

This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.