SearchFragment
open classSearchFragment: Fragment
kotlin.Any | ||
↳ | android.app.Fragment | |
↳ | androidx.leanback.app.SearchFragment |
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 RowsFragment
, 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 | |
---|---|
<init>() A fragment to handle searches. |
Public methods | |
---|---|
open static Bundle! |
createArgs(args: Bundle!, query: String!) |
open static Bundle! |
createArgs(args: Bundle!, query: String!, title: String!) |
open Unit |
displayCompletions(completions: MutableList<String!>!) Displays the completions shown by the IME. |
open Unit |
displayCompletions(completions: Array<CompletionInfo!>!) Displays the completions shown by the IME. |
open Drawable! |
Returns the badge drawable in the search bar. |
open Intent! |
Returns an intent that can be used to request speech recognition. |
open RowsFragment! |
Returns RowsFragment that shows result rows. |
open String! |
getTitle() Returns the title set in the search bar. |
open static SearchFragment! |
newInstance(query: String!) Creates a search fragment with a given search query. |
open Unit | |
open View? |
onCreateView(inflater: LayoutInflater!, container: ViewGroup?, savedInstanceState: Bundle!) |
open Unit | |
open Unit |
onPause() |
open Unit |
onRequestPermissionsResult(requestCode: Int, permissions: Array<String!>, grantResults: IntArray) |
open Unit |
onResume() |
open Unit |
onStart() |
open Unit |
setBadgeDrawable(drawable: Drawable!) 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 |
Sets an item selection listener for the results. |
open Unit |
Sets background color of not-listening state search orb. |
open Unit |
Sets background color of listening state search orb. |
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 |
open Unit |
setSearchResultProvider(searchResultProvider: SearchFragment.SearchResultProvider!) Sets the search provider that is responsible for returning results for the search query. |
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 title string to be be shown in an empty search bar. |
open Unit |
Starts speech recognition. |
Public constructors
<init>
SearchFragment()
Deprecated: use 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 RowsFragment
, 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
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. |
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. |
getBadgeDrawable
open fun getBadgeDrawable(): Drawable!
Returns the badge drawable in the search bar.
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:
RecognizerIntent#EXTRA_LANGUAGE_MODEL
set toRecognizerIntent#LANGUAGE_MODEL_FREE_FORM
RecognizerIntent#EXTRA_PARTIAL_RESULTS
set to trueRecognizerIntent#EXTRA_PROMPT
set to the search bar hint text
setSearchQuery(Intent, boolean)
.
getRowsFragment
open fun getRowsFragment(): RowsFragment!
Returns RowsFragment that shows result rows. RowsFragment is initialized after SearchFragment.onCreateView().
Return | |
---|---|
RowsFragment! |
RowsFragment that shows result rows. |
newInstance
open static fun newInstance(query: String!): SearchFragment!
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 | |
---|---|
SearchFragment! |
A new SearchFragment. |