Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

SearchSupportFragment

open class SearchSupportFragment : Fragment
kotlin.Any
   ↳ androidx.fragment.app.Fragment
   ↳ androidx.leanback.app.SearchSupportFragment

A fragment to handle searches. An application will supply an implementation of the SearchResultProvider interface to handle the search and return an ObjectAdapter containing the results. The results are rendered into a RowsSupportFragment, in the same way that they are in a .

A SpeechRecognizer object will be created for which your application will need to declare android.permission.RECORD_AUDIO in AndroidManifest file. If app's target version is >= 23 and the device version is >= 23, a permission dialog will show first time using speech recognition. 0 will be used as requestCode in requestPermissions() call. setSpeechRecognitionCallback(SpeechRecognitionCallback) is deprecated.

Speech recognition is automatically started when fragment is created, but not when fragment is restored from an instance state. Activity may manually call startRecognition(), typically in onNewIntent().

Summary

Nested classes
abstract

Search API to be provided by the application.

Public constructors

A fragment to handle searches.

Public methods
open Unit

Sets the badge drawable that will be shown inside the search bar next to the title.

open Unit

Sets an item clicked listener for the results.

open Unit

open Unit

Sets background color of listening state search orb.

open Drawable!

Returns the badge drawable in the search bar.

open Unit

Starts speech recognition.

open Unit
setSearchQuery(query: String!, submit: Boolean)

Sets the text of the search query and optionally submits the query.

open Unit
setSearchQuery(intent: Intent!, submit: Boolean)

Sets the text of the search query based on the RecognizerIntent#EXTRA_RESULTS in the given intent, and optionally submit the query.

open Unit

Sets an item selection listener for the results.

open Intent!

Returns an intent that can be used to request speech recognition.

open String!

Returns the title set in the search bar.

open Unit

open Unit

Displays the completions shown by the IME.

open Unit

Displays the completions shown by the IME.

open Unit

Sets background color of not-listening state search orb.

open RowsSupportFragment!

Returns RowsSupportFragment that shows result rows.

open Unit
onCreate(savedInstanceState: Bundle?)

open Unit

open Unit
onRequestPermissionsResult(requestCode: Int, permissions: Array<String!>, grantResults: IntArray)

open Unit

open Unit
setTitle(title: String!)

Sets the title string to be be shown in an empty search bar.

open View?
onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?)

open Unit

Sets this callback to have the fragment pass speech recognition requests to the activity rather than using a SpeechRecognizer object.

open Unit

Sets the search provider that is responsible for returning results for the search query.

open static Bundle!
createArgs(args: Bundle!, query: String!)

open static Bundle!
createArgs(args: Bundle!, query: String!, title: String!)

open static SearchSupportFragment!

Creates a search fragment with a given search query.

Inherited functions

Public constructors

<init>

SearchSupportFragment()

A fragment to handle searches. An application will supply an implementation of the SearchResultProvider interface to handle the search and return an ObjectAdapter containing the results. The results are rendered into a RowsSupportFragment, in the same way that they are in a .

A SpeechRecognizer object will be created for which your application will need to declare android.permission.RECORD_AUDIO in AndroidManifest file. If app's target version is >= 23 and the device version is >= 23, a permission dialog will show first time using speech recognition. 0 will be used as requestCode in requestPermissions() call. setSpeechRecognitionCallback(SpeechRecognitionCallback) is deprecated.

Speech recognition is automatically started when fragment is created, but not when fragment is restored from an instance state. Activity may manually call startRecognition(), typically in onNewIntent().

Public methods

setBadgeDrawable

open fun setBadgeDrawable(drawable: Drawable!): Unit

Sets the badge drawable that will be shown inside the search bar next to the title.

setOnItemViewClickedListener

open fun setOnItemViewClickedListener(listener: OnItemViewClickedListener!): Unit

Sets an item clicked listener for the results.

Parameters
listener OnItemViewClickedListener!: The item clicked listener to be invoked when an item in the search results is clicked.

onPause

open fun onPause(): Unit

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 in the search bar.

startRecognition

open fun startRecognition(): Unit

Starts speech recognition. Typical use case is that activity receives onNewIntent() call when user clicks a MIC button. Note that SearchSupportFragment automatically starts speech recognition at first time created, there is no need to call startRecognition() when fragment is created.

setSearchQuery

open fun setSearchQuery(query: String!, submit: Boolean): Unit

Sets the text of the search query and optionally submits the query. Either onQueryTextChange or onQueryTextSubmit will be called on the provider if it is set.

Parameters
query String!: The search query to set.
submit String!: Whether to submit the query.

setSearchQuery

open fun setSearchQuery(intent: Intent!, submit: Boolean): Unit

Sets the text of the search query based on the RecognizerIntent#EXTRA_RESULTS in the given intent, and optionally submit the query. If more than one result is present in the results list, the first will be used.

Parameters
intent Intent!: Intent received from a speech recognition service.
submit Intent!: Whether to submit the query.

setOnItemViewSelectedListener

open fun setOnItemViewSelectedListener(listener: OnItemViewSelectedListener!): Unit

Sets an item selection listener for the results.

Parameters
listener OnItemViewSelectedListener!: The item selection listener to be invoked when an item in the search results is selected.

getRecognizerIntent

open fun getRecognizerIntent(): Intent!

Returns an intent that can be used to request speech recognition. Built from the base RecognizerIntent#ACTION_RECOGNIZE_SPEECH plus extras:

For handling the intent returned from the service, see setSearchQuery(Intent, boolean).

getTitle

open fun getTitle(): String!

Returns the title set in the search bar.

onDestroy

open fun onDestroy(): Unit

displayCompletions

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

Displays the completions shown by the IME. An application may provide a list of query completions that the system will show in the IME.

Parameters
completions MutableList<String!>!: A list of completions to show in the IME. Setting to null or empty will clear the list.

displayCompletions

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

Displays the completions shown by the IME. An application may provide a list of query completions that the system will show in the IME.

Parameters
completions Array<CompletionInfo!>!: A list of completions to show in the IME. Setting to null or empty will clear the list.

setSearchAffordanceColors

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

Sets background color of not-listening state search orb.

Parameters
colors SearchOrbView.Colors!: SearchOrbView.Colors.

getRowsSupportFragment

open fun getRowsSupportFragment(): RowsSupportFragment!

Returns RowsSupportFragment that shows result rows. RowsSupportFragment is initialized after SearchSupportFragment.onCreateView().

Return
RowsSupportFragment!: RowsSupportFragment that shows result rows.

onCreate

open fun onCreate(savedInstanceState: Bundle?): Unit

onStart

open fun onStart(): Unit

onRequestPermissionsResult

open fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String!>, grantResults: IntArray): Unit

onResume

open fun onResume(): Unit

setTitle

open fun setTitle(title: String!): Unit

Sets the title string to be be shown in an empty search bar. The title may be placed in a call-to-action, such as "Search title" or "Speak to search title".

onCreateView

open fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View?

setSpeechRecognitionCallback

open fun setSpeechRecognitionCallback(callback: SpeechRecognitionCallback!): Unit

Sets this callback to have the fragment pass speech recognition requests to the activity rather than using a SpeechRecognizer object.

setSearchResultProvider

open fun setSearchResultProvider(searchResultProvider: SearchSupportFragment.SearchResultProvider!): Unit

Sets the search provider that is responsible for returning results for the search query.

createArgs

open static fun createArgs(args: Bundle!, query: String!): Bundle!
Parameters
args Bundle!: Bundle to use for the arguments, if null a new Bundle will be created.

createArgs

open static fun createArgs(args: Bundle!, query: String!, title: String!): Bundle!

newInstance

open static fun newInstance(query: String!): SearchSupportFragment!

Creates a search fragment with a given search query.

You should only use this if you need to start the search fragment with a pre-filled query.

Parameters
query String!: The search query to begin with.
Return
SearchSupportFragment!: A new SearchSupportFragment.