{"id":1328,"date":"2016-02-26T11:51:12","date_gmt":"2016-02-26T03:51:12","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=1328"},"modified":"2026-08-18T12:58:49","modified_gmt":"2026-08-18T04:58:49","slug":"android-%e6%b5%ae%e5%8a%a8%e6%90%9c%e7%b4%a2%e6%a1%86-searchable-%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=1328","title":{"rendered":"Android \u6d6e\u52a8\u641c\u7d22\u6846 searchable \u4f7f\u7528"},"content":{"rendered":"<section id=\"wenyan\" style=\"font-family: system-ui, 'Apple Color Emoji', 'Segoe UI', 'Segoe UI Symbol', 'Noto Sans', Roboto, sans-serif; line-height: 1.75; font-size: 16px; color: #000000; caret-color: #000000;\" data-provider=\"WenYan\">\n<blockquote style=\"margin: 20px 0px; display: block; font-size: 0.9em; overflow: auto; border-left: 3px solid #ef7060; color: #6a737d; padding: 10px 10px 10px 20px; background: #fff9f9;\">\n<p style=\"margin: 1em 0px;\">Android \u7ed9\u641c\u7d22\u63d0\u4f9b\u4e86\u7edf\u4e00\u63a5\u53e3\uff1asearch dialog \u548c search widget\u3002\u672c\u6587\u53ea\u8bb2 search dialog\u2014\u2014\u5b83\u53ea\u80fd\u51fa\u73b0\u5728 Activity \u7a97\u53e3\u4e0a\u65b9\u3002\u4e0b\u9762\u4ee5\u70b9\u51fb EditText \u542f\u52a8\u641c\u7d22\u6846\u4e3a\u4f8b\u3002<\/p>\n<\/blockquote>\n<p><!--more--><\/p>\n<p style=\"margin: 1em 0px;\">\u6548\u679c\u5982\u4e0b\uff1a<\/p>\n<p style=\"margin: 1em 0px;\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-1329\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2016\/02\/search1.gif\" alt=\"search1\" width=\"343\" height=\"298\" \/><\/p>\n<hr>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid #ef7060; display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: #ef7060; color: #ffffff; padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u4e00\u3001searchable.xml<\/span><\/h2>\n<p style=\"margin: 1em 0px;\">\u65b0\u5efa <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">searchable.xml<\/code>\uff0c\u653e\u5728 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">res\/xml<\/code>\uff0c\u914d\u7f6e\u641c\u7d22\u6846\u5c5e\u6027\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;\n&lt;searchable xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot;\n    android:label=&quot;@string\/app_name&quot;\n    android:hint=&quot;@string\/search_hint&quot;\/&gt;<\/code><\/pre>\n<ul style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: disc;\">\n<li>\n<section><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">android:label<\/code> \u662f\u552f\u4e00\u5fc5\u987b\u9879\uff0c\u6307\u5411\u5e94\u7528\u540d\u3002\u5b9e\u9645\u4e0a\u53ea\u6709\u5728 Quick Search Box \u7684 search suggestions \u53ef\u7528\u65f6\u624d\u770b\u5f97\u89c1<\/section>\n<\/li>\n<li>\n<section><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">android:hint<\/code> \u4e0d\u662f\u5fc5\u987b\uff0c\u4f46\u5efa\u8bae\u603b\u662f\u5199\u4e0a\uff0c\u662f\u8f93\u5165\u524d\u7684\u63d0\u793a\u8bed<\/section>\n<\/li>\n<\/ul>\n<p style=\"margin: 1em 0px;\">\u5176\u5b83\u5c5e\u6027\u89c1\u5b98\u65b9\u6587\u6863\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;\n&lt;searchable xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot;\n    android:label=&quot;string resource&quot;\n    android:hint=&quot;string resource&quot;\n    android:searchMode=[&quot;queryRewriteFromData&quot; | &quot;queryRewriteFromText&quot;]\n    android:searchButtonText=&quot;string resource&quot;\n    android:inputType=&quot;inputType&quot;\n    android:imeOptions=&quot;imeOptions&quot;\n    android:searchSuggestAuthority=&quot;string&quot;\n    android:searchSuggestPath=&quot;string&quot;\n    android:searchSuggestSelection=&quot;string&quot;\n    android:searchSuggestIntentAction=&quot;string&quot;\n    android:searchSuggestIntentData=&quot;string&quot;\n    android:searchSuggestThreshold=&quot;int&quot;\n    android:includeInGlobalSearch=[&quot;true&quot; | &quot;false&quot;]\n    android:searchSettingsDescription=&quot;string resource&quot;\n    android:queryAfterZeroResults=[&quot;true&quot; | &quot;false&quot;]\n    android:voiceSearchMode=[&quot;showVoiceSearchButton&quot; | &quot;launchWebSearch&quot; | &quot;launchRecognizer&quot;]\n    android:voiceLanguageModel=[&quot;free-form&quot; | &quot;web_search&quot;]\n    android:voicePromptText=&quot;string resource&quot;\n    android:voiceLanguage=&quot;string&quot;\n    android:voiceMaxResults=&quot;int&quot;\n    &gt;\n    &lt;actionkey\n        android:keycode=&quot;KEYCODE&quot;\n        android:queryActionMsg=&quot;string&quot;\n        android:suggestActionMsg=&quot;string&quot;\n        android:suggestActionMsgColumn=&quot;string&quot; &gt;\n&lt;\/searchable&gt;<\/code><\/pre>\n<hr>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid #ef7060; display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: #ef7060; color: #ffffff; padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u4e8c\u3001Manifest \u58f0\u660e Searchable Activity<\/span><\/h2>\n<p style=\"margin: 1em 0px;\">\u641c\u7d22\u7ed3\u679c Activity \u53ef\u4ee5\u662f\u5f53\u524d\u9875\uff0c\u4e5f\u53ef\u4ee5\u5355\u72ec\u4e00\u4e2a\u3002\u8fd9\u91cc\u76f4\u63a5\u7528\u5f53\u524d SearchActivity\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;application\n    android:allowBackup=&quot;true&quot;\n    android:icon=&quot;@mipmap\/ic_launcher&quot;\n    android:label=&quot;@string\/app_name&quot;\n    android:supportsRtl=&quot;true&quot;\n    android:theme=&quot;@style\/AppTheme&quot;&gt;\n    &lt;meta-data\n        android:name=&quot;android.app.default_searchable&quot;\n        android:value=&quot;.SearchActivity&quot;\/&gt;\n\n    &lt;activity android:name=&quot;.SearchActivity&quot;&gt;\n        &lt;intent-filter&gt;\n            &lt;action android:name=&quot;android.intent.action.MAIN&quot; \/&gt;\n            &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; \/&gt;\n        &lt;\/intent-filter&gt;\n        &lt;intent-filter&gt;\n            &lt;action android:name=&quot;android.intent.action.SEARCH&quot; \/&gt;\n        &lt;\/intent-filter&gt;\n\n        &lt;meta-data\n            android:name=&quot;android.app.searchable&quot;\n            android:resource=&quot;@xml\/searchable&quot; \/&gt;\n    &lt;\/activity&gt;\n&lt;\/application&gt;<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">activity \u5185 meta-data \u7684 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">android:name<\/code> \u5fc5\u987b\u662f <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">android.app.searchable<\/code>\uff0c<code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">android:resource<\/code> \u6307\u5411 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">res\/xml\/searchable.xml<\/code>\u3002<\/p>\n<hr>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid #ef7060; display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: #ef7060; color: #ffffff; padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u4e09\u3001\u542f\u52a8 search dialog<\/span><\/h2>\n<p style=\"margin: 1em 0px;\">Activity \u91cc\u8c03 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">onSearchRequested()<\/code>\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">@Override\npublic void onClick(View v) {\n    switch (v.getId()){\n        case R.id.search_edit:\n            onSearchRequested();\n            break;\n    }\n}<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u641c\u7d22\u524d\u8981\u505a\u522b\u7684\u4e8b\uff0c\u91cd\u5199 onSearchRequested\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">@Override\npublic boolean onSearchRequested() {\n    \/\/\u8fd9\u4e2a\u65b9\u6cd5\u4e2d\u5e72\u4f60\u60f3\u5e72\u7684\u4e8b\n    doSometingOther();\n    return super.onSearchRequested();\n}<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u9700\u8981\u5e26\u53c2\u6570\u65f6\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">public boolean onSearchRequested() {\n    Log.i(TAG,&quot;onSearchRequested------------========&quot;);\n    Bundle appData = new Bundle();\n    appData.putString(&quot;key&quot;, &quot;your info&quot;);\n    startSearch(null, true, appData, false);\n    return true;\n}<\/code><\/pre>\n<hr>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid #ef7060; display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: #ef7060; color: #ffffff; padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u56db\u3001\u53d6\u51fa\u641c\u7d22\u5173\u952e\u5b57<\/span><\/h2>\n<p style=\"margin: 1em 0px;\">\u5173\u952e\u5b57\uff1a<code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">String query = intent.getStringExtra(SearchManager.QUERY);<\/code>\u3002\u53d6\u4e4b\u524d\u5148\u5224\u65ad action \u662f\u5426\u4e3a <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">android.intent.action.SEARCH<\/code>\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">Intent intent = getIntent();\nif (Intent.ACTION_SEARCH.equals(intent.getAction())) {\n    String query = intent.getStringExtra(SearchManager.QUERY);\n}<\/code><\/pre>\n<hr>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid #ef7060; display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: #ef7060; color: #ffffff; padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u4e94\u3001\u7ed3\u679c\u5728\u5f53\u524d\u9875\u5904\u7406\uff1asingleTop + onNewIntent<\/span><\/h2>\n<p style=\"margin: 1em 0px;\">\u7ed3\u679c\u53ef\u4ee5\u5355\u72ec\u4e00\u4e2a\u7c7b\uff0c\u4e5f\u53ef\u4ee5\u5728\u5f53\u524d\u641c\u7d22\u6846\u6240\u5728\u7c7b\u5904\u7406\u3002\u82e5\u5728\u5f53\u524d\u7c7b\u5904\u7406\uff0c\u8981\u8bbe <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">singleTop<\/code>\uff0c\u907f\u514d\u518d\u521b\u5efa Activity\u3002\u8fd9\u65f6 onCreate \u4e0d\u4f1a\u518d\u8d70\uff1b\u82e5\u53ea\u5728 onResume \u91cc <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">getIntent()<\/code>\uff0c\u62ff\u5230\u7684\u8fd8\u662f\u65e7 Intent\uff0caction \u4e0d\u662f SEARCH\u2014\u2014\u641c\u7d22\u540e Intent \u5df2\u7ecf\u53d8\u4e86\uff0cActivity \u91cc\u7f13\u5b58\u7684\u8fd8\u662f\u539f\u6765\u90a3\u4e2a\u3002\u6b63\u786e\u505a\u6cd5\uff1a\u91cd\u5199 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">onNewIntent<\/code>\uff0c<code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">setIntent(intent)<\/code> \u66f4\u65b0\u540e\u518d\u5904\u7406\u3002\u539f\u6587 handleIntent \u8bef\u7528\u4e86 getIntent() \u800c\u4e0d\u662f\u53c2\u6570 intent\uff0c\u8fd9\u91cc\u6309\u53c2\u6570\u4fee\u6b63\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">@Override\nprotected void onCreate(Bundle savedInstanceState) {\n    super.onCreate(savedInstanceState);\n    setContentView(R.layout.activity_search_dialog_layout);\n    mSearchEdit = (EditText) findViewById(R.id.search_edit);\n    mContentTxt = (TextView) findViewById(R.id.search_content_txt);\n    mSearchEdit.setOnClickListener(this);\n    handleIntent(getIntent());\n}\n\n\/** \u91cd\u590d\u5237\u65b0\u5f53\u524d Activity \u65f6\u6267\u884c *\/\n@Override\nprotected void onNewIntent(Intent intent) {\n    setIntent(intent);\n    handleIntent(intent);\n}\n\nprivate void handleIntent(Intent intent) {\n    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {\n        String query = intent.getStringExtra(SearchManager.QUERY);\n        doMySearch(query);\n    }\n}\n\n\/** \u5904\u7406\u641c\u7d22\u7ed3\u679c *\/\npublic void doMySearch(String query){\n    mContentTxt.setText(query);\n}<\/code><\/pre>\n<hr>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid #ef7060; display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: #ef7060; color: #ffffff; padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u516d\u3001\u8bb0\u5f55\u641c\u7d22\u5386\u53f2<\/span><\/h2>\n<p style=\"margin: 1em 0px;\">\u67e5\u5b8c\u5e0c\u671b\u7559\u4e0b\u5173\u952e\u5b57\uff0c\u7528 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">SearchRecentSuggestionsProvider<\/code>\u3002\u5148\u5efa Provider\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">public class SearchSuggestionProvider extends SearchRecentSuggestionsProvider {\n\n    final static String AUTHORITY = &quot;com.debby.googlemap.SuggestionProvider&quot;;\n    final static int MODE = DATABASE_MODE_QUERIES;\n\n    public SearchSuggestionProvider() {\n        super();\n        setupSuggestions(AUTHORITY, MODE);\n    }\n}<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">Manifest \u91cc authorities \u5fc5\u987b\u548c Provider \u4e00\u81f4\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;provider android:name=&quot;com.debby.googlemap.SearchSuggestionProvider&quot;\n    android:authorities=&quot;com.debby.googlemap.SuggestionProvider&quot; \/&gt;<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">Activity \u91cc\u4fdd\u5b58\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this,\n        SearchSuggestionProvider.AUTHORITY, SearchSuggestionProvider.MODE);\nsuggestions.saveRecentQuery(query, null);<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u4e0b\u6b21\u641c\u7d22\u5c31\u80fd\u770b\u5230\u5386\u53f2\u3002<\/p>\n<hr>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid #ef7060; display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: #ef7060; color: #ffffff; padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u4e03\u3001\u6e05\u7a7a\u5386\u53f2<\/span><\/h2>\n<p style=\"margin: 1em 0px;\">\u91cd\u5199 Provider \u7684 query\uff0c\u5728 Cursor \u672b\u5c3e\u52a0\u4e00\u6761\u300c\u6e05\u7a7a\u5386\u53f2\u8bb0\u5f55\u300d\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">@Override\npublic Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder, CancellationSignal cancellationSignal) {\n    String[] items = null;\n    Cursor cursor = super.query(uri, projection, selection, selectionArgs, sortOrder);\n    int arrayLength = cursor.getCount();\n    if (arrayLength != 0) {\n        items = new String[arrayLength + 1];\n        cursor.moveToFirst();\n        int i = 0;\n        for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {\n            int number = cursor.getColumnIndex(&quot;suggest_intent_query&quot;);\n            items[i] = cursor.getString(number);\n            i++;\n        }\n        items[i] = &quot;\u6e05\u7a7a\u5386\u53f2\u8bb0\u5f55&quot;;\n    } else {\n        return null;\n    }\n\n    String[] columns = new String[]{&quot;suggest_format&quot;, &quot;suggest_text_1&quot;, &quot;suggest_intent_query&quot;, &quot;_id&quot;};\n    MatrixCursor stringCursor = new MatrixCursor(columns);\n    String row[] = new String[4];\n    int i = 0;\n    for (CharSequence item : items) {\n        row[0] = &quot;&quot; + 0;\n        row[1] = item.toString();\n        row[2] = item.toString();\n        row[3] = &quot;&quot; + (++i);\n        stringCursor.addRow(row);\n    }\n    return stringCursor;\n}<\/code><\/pre>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2016\/02\/search4.gif\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-1335\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2016\/02\/search4.gif\" alt=\"search4\" width=\"353\" height=\"579\" \/><\/a><\/p>\n<table style=\"border-collapse: collapse; margin: 1.4em auto; max-width: 100%; table-layout: fixed; text-align: left; overflow: auto; display: table; overflow-wrap: break-word; word-break: break-all;\" width=\"817\">\n<thead>\n<tr>\n<th style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top; font-weight: bold; background-color: #fff9f9; color: #ef7060;\">\u6b65\u9aa4<\/th>\n<th style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top; font-weight: bold; background-color: #fff9f9; color: #ef7060;\">\u5173\u952e\u70b9<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">searchable.xml<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">label \u5fc5\u586b\uff0chint \u5efa\u8bae\u586b<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">Manifest<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">SEARCH action + android.app.searchable \u6307\u5411 xml<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u542f\u52a8<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">onSearchRequested \/ startSearch \u53ef\u5e26 Bundle<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u53d6\u5173\u952e\u5b57<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">ACTION_SEARCH + SearchManager.QUERY<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u5f53\u524d\u9875\u51fa\u7ed3\u679c<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">singleTop + onNewIntent + setIntent<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u5386\u53f2<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">SearchRecentSuggestionsProvider \u4fdd\u5b58\/\u6e05\u7a7a<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<blockquote style=\"margin: 20px 0px; display: block; font-size: 0.9em; overflow: auto; border-left: 3px solid #ef7060; color: #6a737d; padding: 10px 10px 10px 20px; background: #fff9f9;\">\n<p style=\"margin: 1em 0px;\"><strong>\u4e00\u53e5\u8bdd\u603b\u7ed3\uff1asearch dialog \u9760 searchable.xml + Manifest\uff1b\u5f53\u524d\u9875\u51fa\u7ed3\u679c\u5fc5\u987b singleTop \u5e76\u5728 onNewIntent \u91cc\u6362 Intent\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>Android \u7ed9\u641c\u7d22\u63d0\u4f9b\u4e86\u7edf\u4e00\u63a5\u53e3\uff1asearch dialog \u548c search widget\u3002\u672c\u6587\u53ea\u8bb2 s [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[79],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/1328"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1328"}],"version-history":[{"count":3,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/1328\/revisions"}],"predecessor-version":[{"id":1344,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/1328\/revisions\/1344"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1328"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1328"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1328"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}