public class SearchView
extends LinearLayout
implements CollapsibleActionView
java.lang.Object | ||||
↳ | android.view.View | |||
↳ | android.view.ViewGroup | |||
↳ | android.widget.LinearLayout | |||
↳ | android.widget.SearchView |
为用户提供用户界面的小部件,用于输入搜索查询并向搜索提供者提交请求。 显示查询建议或结果的列表(如果可用),并允许用户选择要启动的建议或结果。
当在ActionBar中将SearchView用作可折叠菜单项的操作视图时,它需要使用setIconifiedByDefault(true)
默认设置为图标setIconifiedByDefault(true)
。 这是默认设置,所以不需要做任何事情。
如果您希望搜索字段始终可见,请调用setIconifiedByDefault(false)。
有关使用 SearchView
信息,请阅读 Search开发人员指南。
Nested classes |
|
---|---|
interface |
SearchView.OnCloseListener
|
interface |
SearchView.OnQueryTextListener 对查询文本进行更改的回调。 |
interface |
SearchView.OnSuggestionListener 建议选择事件的回调界面。 |
XML attributes |
|
---|---|
android:iconifiedByDefault |
The default state of the SearchView. |
android:imeOptions |
The IME options to set on the query text field. |
android:inputType |
The input type to set on the query text field. |
android:maxWidth |
An optional maximum width of the SearchView. |
android:queryHint |
An optional query hint string to be displayed in the empty query field. |
Inherited XML attributes |
|
---|---|
From class android.widget.LinearLayout
|
|
From class android.view.ViewGroup
|
|
From class android.view.View
|
Inherited constants |
---|
From class android.widget.LinearLayout
|
From class android.view.ViewGroup
|
From class android.view.View
|
Inherited fields |
---|
From class android.view.View
|
Public constructors |
|
---|---|
SearchView(Context context) |
|
SearchView(Context context, AttributeSet attrs) |
|
SearchView(Context context, AttributeSet attrs, int defStyleAttr) |
|
SearchView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) |
Public methods |
|
---|---|
CharSequence |
getAccessibilityClassName() 返回此对象的类名称以用于辅助功能。 |
int |
getImeOptions() 返回在查询文本字段上设置的IME选项。 |
int |
getInputType() 返回查询文本字段中设置的输入类型。 |
int |
getMaxWidth() 如果设置,获取指定的最大宽度(以像素为单位)。 |
CharSequence |
getQuery() 返回当前在文本字段中的查询字符串。 |
CharSequence |
getQueryHint() 返回将在查询文本字段中显示的提示文本。 |
CursorAdapter |
getSuggestionsAdapter() 返回用于建议的适配器(如果有)。 |
boolean |
isIconfiedByDefault() 返回搜索字段的默认图标化状态。 |
boolean |
isIconified() 返回SearchView的当前图标化状态。 |
boolean |
isQueryRefinementEnabled() 返回是否为所有项目或仅特定项目启用查询优化。 |
boolean |
isSubmitButtonEnabled() 返回提交按钮在必要时是启用还是从不显示。 |
void |
onActionViewCollapsed() 当此视图作为操作视图折叠时调用。 |
void |
onActionViewExpanded() 当此视图作为操作视图展开时调用。 |
boolean |
onKeyDown(int keyCode, KeyEvent event) 处理按键事件以处理操作键。 |
void |
onWindowFocusChanged(boolean hasWindowFocus) 当包含此视图的窗口获得或失去焦点时调用。 |
void |
setIconified(boolean iconify) 图标化或扩展SearchView。 |
void |
setIconifiedByDefault(boolean iconified) 设置搜索字段的默认或静止状态。 |
void |
setImeOptions(int imeOptions) 在查询文本字段上设置IME选项。 |
void |
setInputType(int inputType) 在查询文本字段上设置输入类型。 |
void |
setMaxWidth(int maxpixels) 最多可以使视图的像素很宽 |
void |
setOnCloseListener(SearchView.OnCloseListener listener) 设置侦听器以通知用户何时关闭SearchView。 |
void |
setOnQueryTextFocusChangeListener(View.OnFocusChangeListener listener) 设置侦听器以通知查询文本字段的焦点何时更改。 |
void |
setOnQueryTextListener(SearchView.OnQueryTextListener listener) 在SearchView中为用户操作设置侦听器。 |
void |
setOnSearchClickListener(View.OnClickListener listener) 设置侦听器以通知何时按下搜索按钮。 |
void |
setOnSuggestionListener(SearchView.OnSuggestionListener listener) 设置侦听器以通知何时关注或单击建议。 |
void |
setQuery(CharSequence query, boolean submit) 在文本字段中设置查询字符串,并可以选择提交查询。 |
void |
setQueryHint(CharSequence hint) 设置要在查询文本字段中显示的提示文本。 |
void |
setQueryRefinementEnabled(boolean enable) 指定是否应该在每个建议旁边显示查询细化按钮,还是应该依赖于从建议提供程序检索的各个项目中设置的标志。 |
void |
setSearchableInfo(SearchableInfo searchable) 为此SearchView设置SearchableInfo。 |
void |
setSubmitButtonEnabled(boolean enabled) 当查询非空时启用显示提交按钮。 |
void |
setSuggestionsAdapter(CursorAdapter adapter) 如果您愿意,您可以设置一个自定义适配器。 |
Protected methods |
|
---|---|
void |
onDetachedFromWindow() 这是在视图从窗口分离时调用的。 |
void |
onLayout(boolean changed, int left, int top, int right, int bottom) 当这个视图为每个孩子分配一个大小和位置时,从布局调用。 |
void |
onMeasure(int widthMeasureSpec, int heightMeasureSpec) 测量视图及其内容以确定测量宽度和测量高度。 |
void |
onRestoreInstanceState(Parcelable state) 吊钩允许视图重新应用之前由 |
Parcelable |
onSaveInstanceState() 钩子允许视图生成其内部状态的表示,稍后可用于创建具有相同状态的新实例。 |
Inherited methods |
|
---|---|
From class android.widget.LinearLayout
|
|
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
|
|
From interface android.view.CollapsibleActionView
|
SearchView的默认状态。 如果为true,则在不使用时将显示图标,并在点击时展开。
必须是布尔值,即“ true
”或“ false
”。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name
”)或主题属性(形式为“ ?[package:][type:]name
”)的 ?[package:][type:]name
。
这对应于全局属性资源符号 iconifiedByDefault
。
相关方法:
在查询文本字段上设置的IME选项。
必须是以下常量值中的一个或多个(用'|'分隔)。
Constant | Value | 描述 |
---|---|---|
normal |
0x00000000 | There are no special semantics associated with this editor. |
actionUnspecified |
0x00000000 | There is no specific action associated with this editor, let the editor come up with its own if it can. Corresponds to IME_NULL . |
actionNone |
0x00000001 | This editor has no action associated with it. Corresponds to IME_ACTION_NONE . |
actionGo |
0x00000002 | The action key performs a "go" operation to take the user to the target of the text they typed. Typically used, for example, when entering a URL. Corresponds to IME_ACTION_GO . |
actionSearch |
0x00000003 | The action key performs a "search" operation, taking the user to the results of searching for the text the have typed (in whatever context is appropriate). Corresponds to IME_ACTION_SEARCH . |
actionSend |
0x00000004 | The action key performs a "send" operation, delivering the text to its target. This is typically used when composing a message. Corresponds to IME_ACTION_SEND . |
actionNext |
0x00000005 | The action key performs a "next" operation, taking the user to the next field that will accept text. Corresponds to IME_ACTION_NEXT . |
actionDone |
0x00000006 | The action key performs a "done" operation, closing the soft input method. Corresponds to IME_ACTION_DONE . |
actionPrevious |
0x00000007 | The action key performs a "previous" operation, taking the user to the previous field that will accept text. Corresponds to IME_ACTION_PREVIOUS . |
flagNoFullscreen |
0x2000000 | Used to request that the IME never go into fullscreen mode. Applications need to be aware that the flag is not a guarantee, and not all IMEs will respect it. 对应于 |
flagNavigatePrevious |
0x4000000 | Like flagNavigateNext, but specifies there is something interesting that a backward navigation can focus on. If the user selects the IME's facility to backward navigate, this will show up in the application as an actionPrevious at InputConnection.performEditorAction(int) . 对应于 |
flagNavigateNext |
0x8000000 | Used to specify that there is something interesting that a forward navigation can focus on. This is like using actionNext, except allows the IME to be multiline (with an enter key) as well as provide forward navigation. Note that some IMEs may not be able to do this, especially when running on a small screen where there is little space. In that case it does not need to present a UI for this option. Like actionNext, if the user selects the IME's facility to forward navigate, this will show up in the application at InputConnection.performEditorAction(int) . 对应于 |
flagNoExtractUi |
0x10000000 | Used to specify that the IME does not need to show its extracted text UI. For input methods that may be fullscreen, often when in landscape mode, this allows them to be smaller and let part of the application be shown behind. Though there will likely be limited access to the application available from the user, it can make the experience of a (mostly) fullscreen IME less jarring. Note that when this flag is specified the IME may not be set up to be able to display text, so it should only be used in situations where this is not needed. 对应于 |
flagNoAccessoryAction |
0x20000000 | Used in conjunction with a custom action, this indicates that the action should not be available as an accessory button when the input method is full-screen. Note that by setting this flag, there can be cases where the action is simply never available to the user. Setting this generally means that you think showing text being edited is more important than the action you have supplied. |
flagNoEnterAction |
0x40000000 | Used in conjunction with a custom action, this indicates that the action should not be available in-line as a replacement for the "enter" key. Typically this is because the action has such a significant impact or is not recoverable enough that accidentally hitting it should be avoided, such as sending a message. Note that TextView will automatically set this flag for you on multi-line text views. 对应于 |
flagForceAscii |
0x80000000 | Used to request that the IME should be capable of inputting ASCII characters. The intention of this flag is to ensure that the user can type Roman alphabet characters in a TextView used for, typically, account ID or password input. It is expected that IMEs normally are able to input ASCII even without being told so (such IMEs already respect this flag in a sense), but there could be some cases they aren't when, for instance, only non-ASCII input languagaes like Arabic, Greek, Hebrew, Russian are enabled in the IME. Applications need to be aware that the flag is not a guarantee, and not all IMEs will respect it. However, it is strongly recommended for IME authors to respect this flag especially when their IME could end up with a state that has only non-ASCII input languages enabled. 对应于 |
这对应于全局属性资源符号 imeOptions
。
相关方法:
在查询文本字段上设置的输入类型。
必须是以下常量值中的一个或多个(用'|'分隔)。
Constant | Value | 描述 |
---|---|---|
none |
0x00000000 | There is no content type. The text is not editable. |
text |
0x00000001 | Just plain old text. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_NORMAL . |
textCapCharacters |
0x00001001 | Can be combined with text and its variations to request capitalization of all characters. Corresponds to TYPE_TEXT_FLAG_CAP_CHARACTERS . |
textCapWords |
0x00002001 | Can be combined with text and its variations to request capitalization of the first character of every word. Corresponds to TYPE_TEXT_FLAG_CAP_WORDS . |
textCapSentences |
0x00004001 | Can be combined with text and its variations to request capitalization of the first character of every sentence. Corresponds to TYPE_TEXT_FLAG_CAP_SENTENCES . |
textAutoCorrect |
0x00008001 | Can be combined with text and its variations to request auto-correction of text being input. Corresponds to TYPE_TEXT_FLAG_AUTO_CORRECT . |
textAutoComplete |
0x00010001 | Can be combined with text and its variations to specify that this field will be doing its own auto-completion and talking with the input method appropriately. Corresponds to TYPE_TEXT_FLAG_AUTO_COMPLETE . |
textMultiLine |
0x00020001 | Can be combined with text and its variations to allow multiple lines of text in the field. If this flag is not set, the text field will be constrained to a single line. Corresponds to TYPE_TEXT_FLAG_MULTI_LINE . |
textImeMultiLine |
0x00040001 | Can be combined with text and its variations to indicate that though the regular text view should not be multiple lines, the IME should provide multiple lines if it can. Corresponds to TYPE_TEXT_FLAG_IME_MULTI_LINE . |
textNoSuggestions |
0x00080001 | Can be combined with text and its variations to indicate that the IME should not show any dictionary-based word suggestions. Corresponds to TYPE_TEXT_FLAG_NO_SUGGESTIONS . |
textUri |
0x00000011 | Text that will be used as a URI. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_URI . |
textEmailAddress |
0x00000021 | Text that will be used as an e-mail address. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_EMAIL_ADDRESS . |
textEmailSubject |
0x00000031 | Text that is being supplied as the subject of an e-mail. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_EMAIL_SUBJECT . |
textShortMessage |
0x00000041 | Text that is the content of a short message. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_SHORT_MESSAGE . |
textLongMessage |
0x00000051 | Text that is the content of a long message. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_LONG_MESSAGE . |
textPersonName |
0x00000061 | Text that is the name of a person. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_PERSON_NAME . |
textPostalAddress |
0x00000071 | Text that is being supplied as a postal mailing address. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_POSTAL_ADDRESS . |
textPassword |
0x00000081 | Text that is a password. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_PASSWORD . |
textVisiblePassword |
0x00000091 | Text that is a password that should be visible. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_VISIBLE_PASSWORD . |
textWebEditText |
0x000000a1 | Text that is being supplied as text in a web form. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_WEB_EDIT_TEXT . |
textFilter |
0x000000b1 | Text that is filtering some other data. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_FILTER . |
textPhonetic |
0x000000c1 | Text that is for phonetic pronunciation, such as a phonetic name field in a contact entry. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_PHONETIC . |
textWebEmailAddress |
0x000000d1 | Text that will be used as an e-mail address on a web form. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS . |
textWebPassword |
0x000000e1 | Text that will be used as a password on a web form. Corresponds to TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_WEB_PASSWORD . |
number |
0x00000002 | A numeric only field. Corresponds to TYPE_CLASS_NUMBER | TYPE_NUMBER_VARIATION_NORMAL . |
numberSigned |
0x00001002 | Can be combined with number and its other options to allow a signed number. Corresponds to TYPE_CLASS_NUMBER | TYPE_NUMBER_FLAG_SIGNED . |
numberDecimal |
0x00002002 | Can be combined with number and its other options to allow a decimal (fractional) number. Corresponds to TYPE_CLASS_NUMBER | TYPE_NUMBER_FLAG_DECIMAL . |
numberPassword |
0x00000012 | A numeric password field. Corresponds to TYPE_CLASS_NUMBER | TYPE_NUMBER_VARIATION_PASSWORD . |
phone |
0x00000003 | For entering a phone number. Corresponds to TYPE_CLASS_PHONE . |
datetime |
0x00000004 | For entering a date and time. Corresponds to TYPE_CLASS_DATETIME | TYPE_DATETIME_VARIATION_NORMAL . |
date |
0x00000014 | For entering a date. Corresponds to TYPE_CLASS_DATETIME | TYPE_DATETIME_VARIATION_DATE . |
time |
0x00000024 | For entering a time. Corresponds to TYPE_CLASS_DATETIME | TYPE_DATETIME_VARIATION_TIME . |
这对应于全局属性资源符号 inputType
。
相关方法:
SearchView的可选最大宽度。
必须是维度值,这是一个浮点数,后面跟着一个单位,例如“ 14.5sp
”。 可用单位为:px(像素),dp(密度独立像素),sp(基于首选字体大小的缩放像素),单位为英寸,毫米(毫米)。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name
”)或主题属性(形式为“ ?[package:][type:]name
”)的 ?[package:][type:]name
。
这对应于全局属性资源符号 maxWidth
。
相关方法:
一个可选的查询提示字符串,将显示在空白查询字段中。
必须是字符串值,使用'\\;' 转义字符如'\\ n'或'\\ uxxxx'作为unicode字符。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name
”)或主题属性(形式为“ ?[package:][type:]name
”)的 ?[package:][type:]name
。
这对应于全局属性资源符号 queryHint
。
相关方法:
SearchView (Context context, AttributeSet attrs)
Parameters | |
---|---|
context |
Context
|
attrs |
AttributeSet
|
SearchView (Context context, AttributeSet attrs, int defStyleAttr)
Parameters | |
---|---|
context |
Context
|
attrs |
AttributeSet
|
defStyleAttr |
int
|
SearchView (Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
Parameters | |
---|---|
context |
Context
|
attrs |
AttributeSet
|
defStyleAttr |
int
|
defStyleRes |
int
|
CharSequence getAccessibilityClassName ()
返回此对象的类名称以用于辅助功能。 如果子类正在实现的东西应该被视为一个全新的视图类,当它被可访问性使用时,子类只应该覆盖这个子类,与它所源自的类无关。 这用于填写AccessibilityNodeInfo.setClassName
。
Returns | |
---|---|
CharSequence |
int getImeOptions ()
返回在查询文本字段上设置的IME选项。
相关XML属性:
Returns | |
---|---|
int |
the ime options |
也可以看看:
int getInputType ()
返回查询文本字段中设置的输入类型。
相关XML属性:
Returns | |
---|---|
int |
the input type |
int getMaxWidth ()
如果设置,获取指定的最大宽度(以像素为单位)。 如果未指定最大宽度,则返回零。
相关XML属性:
Returns | |
---|---|
int |
the maximum width of the view |
CharSequence getQuery ()
返回当前在文本字段中的查询字符串。
Returns | |
---|---|
CharSequence |
the query string |
CharSequence getQueryHint ()
返回将在查询文本字段中显示的提示文本。
显示的查询提示按以下顺序选择:
setQueryHint(CharSequence)
android:queryHint
SearchableInfo
via getHintId()
相关XML属性:
Returns | |
---|---|
CharSequence |
the displayed query hint text, or null if none set |
CursorAdapter getSuggestionsAdapter ()
返回用于建议的适配器(如果有)。
Returns | |
---|---|
CursorAdapter |
the suggestions adapter |
boolean isIconfiedByDefault ()
返回搜索字段的默认图标化状态。
相关XML属性:
Returns | |
---|---|
boolean |
boolean isIconified ()
返回SearchView的当前图标化状态。
Returns | |
---|---|
boolean |
true if the SearchView is currently iconified, false if the search field is fully visible. |
boolean isQueryRefinementEnabled ()
返回是否为所有项目或仅特定项目启用查询优化。
Returns | |
---|---|
boolean |
true if enabled for all items, false otherwise. |
boolean isSubmitButtonEnabled ()
返回提交按钮在必要时是启用还是从不显示。
Returns | |
---|---|
boolean |
whether the submit button is enabled automatically when necessary |
void onActionViewCollapsed ()
当此视图作为操作视图折叠时调用。 见collapseActionView()
。
void onActionViewExpanded ()
当此视图作为操作视图展开时调用。 见expandActionView()
。
boolean onKeyDown (int keyCode, KeyEvent event)
处理按键事件以处理操作键。
Parameters | |
---|---|
keyCode |
int : This is the keycode of the typed key, and is the same value as found in the KeyEvent parameter. |
event |
KeyEvent : The complete event record for the typed key |
Returns | |
---|---|
boolean |
true if the event was handled here, or false if not. |
void onWindowFocusChanged (boolean hasWindowFocus)
当包含此视图的窗口获得或失去焦点时调用。 请注意,这与视图焦点不同:要接收关键事件,视图和其窗口都必须具有焦点。 如果一个窗口显示在需要输入焦点的窗口上,那么您自己的窗口将失去焦点,但视图焦点将保持不变。
Parameters | |
---|---|
hasWindowFocus |
boolean : True if the window containing this view now has focus, false otherwise. |
void setIconified (boolean iconify)
图标化或扩展SearchView。 图标化后,任何查询文本都会被清除。 这是一个临时状态,不会覆盖由setIconifiedByDefault(boolean)
设置的默认图标化状态。 如果默认状态是图标化的,那么此处的错误将仅在用户关闭该字段之前有效。 如果默认状态被展开,那么这里的真实只会清除文本字段而不会关闭它。
Parameters | |
---|---|
iconify |
boolean : a true value will collapse the SearchView to an icon, while a false will expand it. |
void setIconifiedByDefault (boolean iconified)
设置搜索字段的默认或静止状态。 如果为true,则默认显示单个搜索图标,并在按下时展开以显示文本字段和其他按钮。 另外,如果默认状态为图标化,则当按下关闭按钮时,它会折叠到该状态。 此属性的更改将立即生效。
默认值是true。
相关XML属性:
Parameters | |
---|---|
iconified |
boolean : whether the search field should be iconified by default |
void setImeOptions (int imeOptions)
在查询文本字段上设置IME选项。
相关XML属性:
Parameters | |
---|---|
imeOptions |
int : the options to set on the query text field |
也可以看看:
void setInputType (int inputType)
在查询文本字段上设置输入类型。
相关XML属性:
Parameters | |
---|---|
inputType |
int : the input type to set on the query text field |
也可以看看:
void setMaxWidth (int maxpixels)
最多可以使视图的像素很宽
相关XML属性:
Parameters | |
---|---|
maxpixels |
int
|
void setOnCloseListener (SearchView.OnCloseListener listener)
设置侦听器以通知用户何时关闭SearchView。
Parameters | |
---|---|
listener |
SearchView.OnCloseListener : the listener to call when the user closes the SearchView. |
void setOnQueryTextFocusChangeListener (View.OnFocusChangeListener listener)
设置侦听器以通知查询文本字段的焦点何时更改。
Parameters | |
---|---|
listener |
View.OnFocusChangeListener : the listener to inform of focus changes. |
void setOnQueryTextListener (SearchView.OnQueryTextListener listener)
在SearchView中为用户操作设置侦听器。
Parameters | |
---|---|
listener |
SearchView.OnQueryTextListener : the listener object that receives callbacks when the user performs actions in the SearchView such as clicking on buttons or typing a query. |
void setOnSearchClickListener (View.OnClickListener listener)
设置侦听器以通知何时按下搜索按钮。 这仅在文本字段默认不可见时才有用。 调用setIconified(false)
也会导致通知此侦听器。
Parameters | |
---|---|
listener |
View.OnClickListener : the listener to inform when the search button is clicked or the text field is programmatically de-iconified. |
void setOnSuggestionListener (SearchView.OnSuggestionListener listener)
设置侦听器以通知何时关注或单击建议。
Parameters | |
---|---|
listener |
SearchView.OnSuggestionListener : the listener to inform of suggestion selection events. |
void setQuery (CharSequence query, boolean submit)
在文本字段中设置查询字符串,并可以选择提交查询。
Parameters | |
---|---|
query |
CharSequence : the query string. This replaces any query text already present in the text field. |
submit |
boolean : whether to submit the query right now or only update the contents of text field. |
void setQueryHint (CharSequence hint)
设置要在查询文本字段中显示的提示文本。 这将覆盖SearchableInfo
指定的任何提示。
此值可能被指定为空字符串以防止显示任何查询提示。
相关XML属性:
Parameters | |
---|---|
hint |
CharSequence : the hint text to display or null to clear |
void setQueryRefinementEnabled (boolean enable)
指定是否应该在每个建议旁边显示查询细化按钮,还是应该依赖于从建议提供程序检索的各个项目中设置的标志。 点击查询优化按钮将查询文本字段中的文本替换为来自建议的文本。 如果已使用setSearchableInfo(SearchableInfo)
指定setSearchableInfo(SearchableInfo)
,而不使用自定义适配器,则此标志仅生效。
Parameters | |
---|---|
enable |
boolean : true if all items should have a query refinement button, false if only those items that have a query refinement flag set should have the button. |
void setSearchableInfo (SearchableInfo searchable)
为此SearchView设置SearchableInfo。 SearchableInfo中的属性用于显示标签,提示,建议,创建启动搜索结果屏幕和控制其他功能(如语音按钮)的意图。
Parameters | |
---|---|
searchable |
SearchableInfo : a SearchableInfo can be retrieved from the SearchManager, for a specific activity or a global search provider. |
void setSubmitButtonEnabled (boolean enabled)
当查询非空时启用显示提交按钮。 如果SearchView用于过滤当前活动的内容并且不启动单独的结果活动,则应该禁用提交按钮。
Parameters | |
---|---|
enabled |
boolean : true to show a submit button for submitting queries, false if a submit button is not required. |
void setSuggestionsAdapter (CursorAdapter adapter)
如果您愿意,您可以设置一个自定义适配器。 否则,默认适配器将用于显示来自与SearchableInfo关联的建议提供程序的建议。
Parameters | |
---|---|
adapter |
CursorAdapter
|
void onLayout (boolean changed, int left, int top, int right, int bottom)
当这个视图为每个孩子分配一个大小和位置时,从布局调用。 带孩子的派生类应该覆盖这个方法,并调用他们每个孩子的布局。
Parameters | |
---|---|
changed |
boolean : This is a new size or position for this view |
left |
int : Left position, relative to parent |
top |
int : Top position, relative to parent |
right |
int : Right position, relative to parent |
bottom |
int : Bottom position, relative to parent |
void onMeasure (int widthMeasureSpec, int heightMeasureSpec)
测量视图及其内容以确定测量宽度和测量高度。 此方法由measure(int, int)
调用, measure(int, int)
子类覆盖以提供其内容的准确和有效的度量。
合同:覆盖此方法时, 必须致电setMeasuredDimension(int, int)
来存储此视图的测量宽度和高度。 如果不这样做,将触发IllegalStateException
,由measure(int, int)
引发。 调用超类' onMeasure(int, int)
是一个有效的用法。
Measure的基类实现默认为背景大小,除非MeasureSpec允许更大的大小。 子类应该覆盖onMeasure(int, int)
以提供更好的内容度量。
如果此方法被覆盖,则子类的责任是确保测量的高度和宽度至少为视图的最小高度和宽度( getSuggestedMinimumHeight()
和 getSuggestedMinimumWidth()
)。
Parameters | |
---|---|
widthMeasureSpec |
int : horizontal space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec . |
heightMeasureSpec |
int : vertical space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec . |
void onRestoreInstanceState (Parcelable state)
吊钩允许视图重新应用之前由onSaveInstanceState()
生成的内部状态的表示。 这个函数永远不会被调用为null状态。
Parameters | |
---|---|
state |
Parcelable : The frozen state that had previously been returned by onSaveInstanceState() . |
Parcelable onSaveInstanceState ()
钩子允许视图生成其内部状态的表示,稍后可用于创建具有相同状态的新实例。 此状态应仅包含不持久或以后不能重建的信息。 例如,您永远不会将当前位置存储在屏幕上,因为当视图的新实例放置在其视图层次结构中时会再次计算该位置。
您可能在此处存储的某些示例:文本视图中的当前光标位置(但通常不是文本本身,因为它存储在内容提供程序或其他永久性存储中),即当前在列表视图中选择的项目。
Returns | |
---|---|
Parcelable |
Returns a Parcelable object containing the view's current dynamic state, or null if there is nothing interesting to save. The default implementation returns null. |