Android APIs
public class

SearchBar

extends RelativeLayout
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.RelativeLayout
         ↳ android.support.v17.leanback.widget.SearchBar

Class Overview

SearchBar is a search widget.

Note: Your application will need to request android.permission.RECORD_AUDIO

Summary

Nested Classes
interface SearchBar.SearchBarListener Listener for search query changes  
[Expand]
Inherited XML Attributes
From class android.widget.RelativeLayout
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Constants
From class android.widget.RelativeLayout
From class android.view.ViewGroup
From class android.view.View
[Expand]
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(List<String> completions)
Update the completion list shown by the IME
Drawable getBadgeDrawable()
Returns the badge drawable
String getTitle()
Returns the current title
void setBadgeDrawable(Drawable drawable)
Set the badge drawable showing inside the search bar.
void setSearchBarListener(SearchBar.SearchBarListener listener)
Set a listener for when the term search changes
void setSearchQuery(String query)
Set the search query
void setSpeechRecognizer(SpeechRecognizer recognizer)
Set the speech recognizer to be used when doing voice search.
void setTitle(String title)
Set the title text used in the hint shown in the search bar.
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.
[Expand]
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.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.ViewManager
From interface android.view.ViewParent
From interface android.view.accessibility.AccessibilityEventSource

Public Constructors

public SearchBar (Context context)

public SearchBar (Context context, AttributeSet attrs)

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

Public Methods

public void displayCompletions (List<String> completions)

Update the completion list shown by the IME

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

public Drawable getBadgeDrawable ()

Returns the badge drawable

public String getTitle ()

Returns the current title

public void setBadgeDrawable (Drawable drawable)

Set the badge drawable showing inside the search bar.

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

public void setSearchBarListener (SearchBar.SearchBarListener listener)

Set a listener for when the term search changes

public void setSearchQuery (String query)

Set the search query

Parameters
query the search query to use

public void setSpeechRecognizer (SpeechRecognizer recognizer)

Set 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 a SpeechRecognizer

public void setTitle (String title)

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

Parameters
title The hint to use.

Protected Methods

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

protected void onDetachedFromWindow ()

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

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