belongs to Maven artifact com.android.support:leanback-v17:28.0.0-alpha1
Deprecated since version 27.1.0
SearchFragment
public
class
SearchFragment
extends Fragment
java.lang.Object | ||
↳ | android.app.Fragment | |
↳ | android.support.v17.leanback.app.SearchFragment |
This class was deprecated
in API level 27.1.0.
use SearchSupportFragment
A fragment to handle searches. An application will supply an implementation
of the SearchFragment.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 BrowseFragment
.
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 | |
---|---|
interface |
SearchFragment.SearchResultProvider
Search API to be provided by the application. |
Inherited constants |
---|
From
interface
android.content.ComponentCallbacks2
|
Public constructors | |
---|---|
SearchFragment()
|
Public methods | |
---|---|
static
Bundle
|
createArgs(Bundle args, String query, String title)
|
static
Bundle
|
createArgs(Bundle args, String query)
|
void
|
displayCompletions(CompletionInfo[] completions)
Displays the completions shown by the IME. |
void
|
displayCompletions(List<String> completions)
Displays the completions shown by the IME. |
Drawable
|
getBadgeDrawable()
Returns the badge drawable in the search bar. |
Intent
|
getRecognizerIntent()
Returns an intent that can be used to request speech recognition. |
RowsFragment
|
getRowsFragment()
Returns RowsFragment that shows result rows. |
String
|
getTitle()
Returns the title set in the search bar. |
static
SearchFragment
|
newInstance(String query)
Creates a search fragment with a given search query. |
void
|
onCreate(Bundle savedInstanceState)
|
View
|
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
|
void
|
onDestroy()
|
void
|
onPause()
|
void
|
onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)
|
void
|
onResume()
|
void
|
onStart()
|
void
|
setBadgeDrawable(Drawable drawable)
Sets the badge drawable that will be shown inside the search bar next to the title. |
void
|
setOnItemViewClickedListener(OnItemViewClickedListener listener)
Sets an item clicked listener for the results. |
void
|
setOnItemViewSelectedListener(OnItemViewSelectedListener listener)
Sets an item selection listener for the results. |
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
|
setSearchQuery(String query, boolean submit)
Sets the text of the search query and optionally submits the query. |
void
|
setSearchQuery(Intent intent, boolean submit)
Sets the text of the search query based on the |
void
|
setSearchResultProvider(SearchFragment.SearchResultProvider searchResultProvider)
Sets the search provider that is responsible for returning results for the search query. |
void
|
setSpeechRecognitionCallback(SpeechRecognitionCallback callback)
This method was deprecated in API level 27.1.0. Launching voice recognition activity is no longer supported. App should declare android.permission.RECORD_AUDIO in AndroidManifest file. |
void
|
setTitle(String title)
Sets the title string to be be shown in an empty search bar. |
void
|
startRecognition()
Starts speech recognition. |
Inherited methods | |
---|---|
From
class
android.app.Fragment
| |
From
class
java.lang.Object
| |
From
interface
android.content.ComponentCallbacks2
| |
From
interface
android.view.View.OnCreateContextMenuListener
| |
From
interface
android.content.ComponentCallbacks
|
Public constructors
Public methods
createArgs
Bundle createArgs (Bundle args, String query, String title)
Parameters | |
---|---|
args |
Bundle |
query |
String |
title |
String |
Returns | |
---|---|
Bundle |
createArgs
Bundle createArgs (Bundle args, String query)
Parameters | |
---|---|
args |
Bundle : Bundle to use for the arguments, if null a new Bundle will be created.
|
query |
String |
Returns | |
---|---|
Bundle |
displayCompletions
void displayCompletions (CompletionInfo[] completions)
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 |
CompletionInfo : A list of completions to show in the IME. Setting to
null or empty will clear the list.
|
displayCompletions
void displayCompletions (List<String> completions)
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 |
List : A list of completions to show in the IME. Setting to
null or empty will clear the list.
|
getBadgeDrawable
Drawable getBadgeDrawable ()
Returns the badge drawable in the search bar.
Returns | |
---|---|
Drawable |
getRecognizerIntent
Intent getRecognizerIntent ()
Returns an intent that can be used to request speech recognition.
Built from the base ACTION_RECOGNIZE_SPEECH
plus
extras:
EXTRA_LANGUAGE_MODEL
set toLANGUAGE_MODEL_FREE_FORM
EXTRA_PARTIAL_RESULTS
set to trueEXTRA_PROMPT
set to the search bar hint text
setSearchQuery(Intent, boolean)
.
Returns | |
---|---|
Intent |
getRowsFragment
RowsFragment getRowsFragment ()
Returns RowsFragment that shows result rows. RowsFragment is initialized after SearchFragment.onCreateView().
Returns | |
---|---|
RowsFragment |
RowsFragment that shows result rows. |
getTitle
String getTitle ()
Returns the title set in the search bar.
Returns | |
---|---|
String |
newInstance
SearchFragment newInstance (String query)
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. |
Returns | |
---|---|
SearchFragment |
A new SearchFragment. |
onCreateView
View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
Parameters | |
---|---|
inflater |
LayoutInflater |
container |
ViewGroup |
savedInstanceState |
Bundle |
Returns | |
---|---|
View |
onDestroy
void onDestroy ()
onPause
void onPause ()
onRequestPermissionsResult
void onRequestPermissionsResult (int requestCode, String[] permissions, int[] grantResults)
Parameters | |
---|---|
requestCode |
int |
permissions |
String |
grantResults |
int |
onResume
void onResume ()
onStart
void onStart ()
setBadgeDrawable
void setBadgeDrawable (Drawable drawable)
Sets the badge drawable that will be shown inside the search bar next to the title.
Parameters | |
---|---|
drawable |
Drawable |
setOnItemViewClickedListener
void setOnItemViewClickedListener (OnItemViewClickedListener listener)
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.
|
setOnItemViewSelectedListener
void setOnItemViewSelectedListener (OnItemViewSelectedListener listener)
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.
|
setSearchAffordanceColors
void setSearchAffordanceColors (SearchOrbView.Colors colors)
Sets background color of not-listening state search orb.
Parameters | |
---|---|
colors |
SearchOrbView.Colors : SearchOrbView.Colors.
|
setSearchAffordanceColorsInListening
void setSearchAffordanceColorsInListening (SearchOrbView.Colors colors)
Sets background color of listening state search orb.
Parameters | |
---|---|
colors |
SearchOrbView.Colors : SearchOrbView.Colors.
|
setSearchQuery
void setSearchQuery (String query, boolean submit)
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 |
boolean : Whether to submit the query.
|
setSearchQuery
void setSearchQuery (Intent intent, boolean submit)
Sets the text of the search query based on the 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 |
boolean : Whether to submit the query.
|
setSearchResultProvider
void setSearchResultProvider (SearchFragment.SearchResultProvider searchResultProvider)
Sets the search provider that is responsible for returning results for the search query.
Parameters | |
---|---|
searchResultProvider |
SearchFragment.SearchResultProvider |
setSpeechRecognitionCallback
void setSpeechRecognitionCallback (SpeechRecognitionCallback callback)
This method was deprecated
in API level 27.1.0.
Launching voice recognition activity is no longer supported. App should declare
android.permission.RECORD_AUDIO in AndroidManifest file.
Sets this callback to have the fragment pass speech recognition requests to the activity rather than using a SpeechRecognizer object.
Parameters | |
---|---|
callback |
SpeechRecognitionCallback |
setTitle
void setTitle (String title)
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".
Parameters | |
---|---|
title |
String |
startRecognition
void startRecognition ()
Starts speech recognition. Typical use case is that activity receives onNewIntent() call when user clicks a MIC button. Note that SearchFragment automatically starts speech recognition at first time created, there is no need to call startRecognition() when fragment is created.
Interfaces
- BrowseFragment.FragmentHost
- BrowseFragment.MainFragmentAdapterProvider
- BrowseFragment.MainFragmentRowsAdapterProvider
- BrowseSupportFragment.FragmentHost
- BrowseSupportFragment.MainFragmentAdapterProvider
- BrowseSupportFragment.MainFragmentRowsAdapterProvider
- HeadersFragment.OnHeaderClickedListener
- HeadersFragment.OnHeaderViewSelectedListener
- HeadersSupportFragment.OnHeaderClickedListener
- HeadersSupportFragment.OnHeaderViewSelectedListener
- SearchFragment.SearchResultProvider
- SearchSupportFragment.SearchResultProvider
Classes
- BackgroundManager
- BaseFragment
- BaseSupportFragment
- BrandedFragment
- BrandedSupportFragment
- BrowseFragment
- BrowseFragment.BrowseTransitionListener
- BrowseFragment.FragmentFactory
- BrowseFragment.ListRowFragmentFactory
- BrowseFragment.MainFragmentAdapter
- BrowseFragment.MainFragmentAdapterRegistry
- BrowseFragment.MainFragmentRowsAdapter
- BrowseSupportFragment
- BrowseSupportFragment.BrowseTransitionListener
- BrowseSupportFragment.FragmentFactory
- BrowseSupportFragment.ListRowFragmentFactory
- BrowseSupportFragment.MainFragmentAdapter
- BrowseSupportFragment.MainFragmentAdapterRegistry
- BrowseSupportFragment.MainFragmentRowsAdapter
- DetailsFragment
- DetailsFragmentBackgroundController
- DetailsSupportFragment
- DetailsSupportFragmentBackgroundController
- ErrorFragment
- ErrorSupportFragment
- GuidedStepFragment
- GuidedStepSupportFragment
- HeadersFragment
- HeadersSupportFragment
- OnboardingFragment
- OnboardingSupportFragment
- PlaybackFragment
- PlaybackFragmentGlueHost
- PlaybackSupportFragment
- PlaybackSupportFragmentGlueHost
- ProgressBarManager
- RowsFragment
- RowsFragment.MainFragmentAdapter
- RowsFragment.MainFragmentRowsAdapter
- RowsSupportFragment
- RowsSupportFragment.MainFragmentAdapter
- RowsSupportFragment.MainFragmentRowsAdapter
- SearchFragment
- SearchSupportFragment
- VerticalGridFragment
- VerticalGridSupportFragment
- VideoFragment
- VideoFragmentGlueHost
- VideoSupportFragment
- VideoSupportFragmentGlueHost
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-04-11 UTC.