---
title: "Searchable之六（Voice Search和Search Suggestions）"
author: "mmdev"
date: "2011-12-08T11:31:00Z"
tags: []
slug: "searchable-voice-search-search-suggestions"
draft: false
lastmod: "2011-12-10T16:20:27Z"
id: 1301563
url: "https://mmdev.iteye.com/blog/1301563"
---

十三，语言搜索（Voice Search）&lt;wbr style="line-height:25px"&gt;&lt;div style="line-height:25px"&gt; &lt;div style="line-height:23px; font-size:13px"&gt;&lt;span style="color:#003366; line-height:23px"&gt;你可以通过在你的searchable配置中添加android:voiceSearchMode属性来实现search dialog或widget语言功能的添加。&lt;/span&gt;&lt;/div&gt; &lt;div style="line-height:23px; font-size:13px"&gt;&lt;span style="color:#003366; line-height:23px"&gt;这样就添加了一个用于启动voice prompt的语音搜索的按钮。一但用户完成了speaking, 这个transcribed search query将传送到你的searchable activity.&lt;/span&gt;&lt;/div&gt; &lt;div style="line-height:23px; font-size:13px; font-weight:bold"&gt;示例11如下：&lt;/div&gt; &lt;div style="line-height:23px; font-size:13px"&gt; &lt;div style="line-height:23px"&gt;&lt;span style="color:#3366ff; line-height:23px"&gt;&lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;/span&gt;&lt;/div&gt; &lt;div style="line-height:23px"&gt;&lt;span style="color:#3366ff; line-height:23px"&gt;&lt;searchable xmlns:android="http://schemas.android.com/apk/res/android"&lt;/span&gt;&lt;/div&gt; &lt;div style="line-height:23px"&gt;&lt;span style="color:#3366ff; line-height:23px"&gt; android:label="@string/search\_label"&lt;/span&gt;&lt;/div&gt; &lt;div style="line-height:23px"&gt;&lt;span style="color:#3366ff; line-height:23px"&gt; android:hint="@string/search\_hint"&lt;/span&gt;&lt;/div&gt; &lt;div style="line-height:23px"&gt; &lt;span style="color:#3366ff; line-height:23px"&gt; &lt;/span&gt;&lt;span style="color:#ff6600; line-height:23px"&gt;android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"&lt;/span&gt;&lt;span style="color:#3366ff; line-height:23px"&gt;&gt;&lt;/span&gt; &lt;/div&gt; &lt;div style="line-height:23px"&gt;&lt;span style="color:#3366ff; line-height:23px"&gt;&lt;/searchable&gt;&lt;/span&gt;&lt;/div&gt; &lt;/div&gt; &lt;div style="line-height:23px; font-size:13px"&gt;&lt;span style="color:#003366; line-height:23px"&gt;第一值"showVoiceSearchButton"用于开启voice search, 第二个值“launchRecognizer,”说明了voice search button应该启动一个recognizer来把transcribed text传递给你的searchable activity.&lt;/span&gt;&lt;/div&gt; &lt;div style="line-height:23px; font-size:13px"&gt;&lt;span style="color:#003366; line-height:23px"&gt;你还可以使用其他的一些属性来定义voice search的行为，比如语言和返回的最大结果数。&lt;/span&gt;&lt;/div&gt; &lt;div style="line-height:23px; font-size:13px"&gt; &lt;span style="color:#003366; line-height:23px"&gt;关于&lt;/span&gt;&lt;span style="line-height:23px; color:rgb(0,51,102)"&gt;voice search的&lt;/span&gt;&lt;span style="color:#003366; line-height:23px"&gt;更多属性请参照&lt;/span&gt;&lt;span style="line-height:22px; font-size:14px"&gt;&lt;a rel="nofollow" href="http://developer.android.com/guide/topics/search/searchable-config.html" style="color:rgb(207,121,28); line-height:25px; text-decoration:none"&gt;Searchable Configuration&lt;/a&gt;&lt;/span&gt; &lt;/div&gt; &lt;div style="line-height:23px; font-size:13px"&gt; &lt;span style="line-height:23px"&gt;注意&lt;/span&gt;：&lt;span style="color:#000080; line-height:23px"&gt;请仔细考虑是否要在你的程序中使用voice search.所有通过voice search按钮的搜索都是直接传送给了你的searchable activity，用户根本没有机会预览transcribed query。需要充分测试语言识别（voice recognition），以便它能识别用户在你的程序中提交的各种请求。&lt;/span&gt; &lt;/div&gt; &lt;div style="line-height:23px; font-size:13px"&gt;&lt;span style="color:#000080; line-height:23px"&gt;&lt;br style="line-height:23px"&gt;&lt;/span&gt;&lt;/div&gt; &lt;div style="line-height:25px"&gt;&lt;span style="line-height:25px"&gt;&lt;span style="font-size:16px; line-height:28px"&gt;十四、Search Suggestions&lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;div style="line-height:25px"&gt; &lt;span style="font-size:13px; line-height:23px"&gt;&lt;/span&gt; &lt;div style="line-height:20px; color:rgb(0,51,102)"&gt;search dialog和the search widget都可以在Android system系统的帮助下，在用户搜索的时候，提供建议搜索词。&lt;/div&gt; &lt;div style="line-height:20px; color:rgb(0,51,102)"&gt;系统将管理suggestions列表并处理用户选中suggestion事件.&lt;/div&gt; &lt;div style="line-height:20px; color:rgb(0,51,102)"&gt;一般你可以提供以下两种建议搜索词：&lt;/div&gt; &lt;div style="line-height:20px"&gt; &lt;span style="line-height:23px"&gt;最近的搜索词&lt;/span&gt;&lt;span style="color:#003366; line-height:23px"&gt;：&lt;/span&gt; &lt;/div&gt; &lt;div style="line-height:20px"&gt; &lt;span style="color:#000080; line-height:23px"&gt;这些搜索词只是你以前的一些搜索关键词。更多的内容请参照&lt;/span&gt;&lt;span style="line-height:23px"&gt;&lt;a rel="nofollow" href="http://developer.android.com/guide/topics/search/adding-recent-query-suggestions.html" style="color:rgb(207,121,28); line-height:23px; text-decoration:none"&gt;Adding Recent Query Suggestions&lt;/a&gt;.&lt;/span&gt; &lt;/div&gt; &lt;div style="line-height:20px"&gt;&lt;span style="line-height:22px; font-size:14px"&gt;&lt;span style="line-height:20px; font-size:13px"&gt;&lt;span style="line-height:23px"&gt;个性化搜索词：&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;div style="line-height:23px"&gt; &lt;div style="line-height:23px"&gt;&lt;span style="color:#000080; line-height:23px"&gt;这些search suggestions都来自于你自己的数据, 它帮助用户快速选择正确的拼写或他们要搜索的项.&lt;/span&gt;&lt;/div&gt; &lt;div style="line-height:23px"&gt; &lt;span style="line-height:23px"&gt;图三&lt;/span&gt;&lt;span style="color:#000080; line-height:23px"&gt;就是来自于dictionary程序一个个性化suggestions的界面图—用户可以选择一个suggestion来很快的得到它的定义。更多内容请参照&lt;/span&gt;&lt;a rel="nofollow" href="http://developer.android.com/guide/topics/search/adding-custom-suggestions.html" style="color:rgb(207,121,28); line-height:23px; text-decoration:none"&gt;Adding Custom Suggestions&lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;div style="line-height:23px"&gt;&lt;span style="line-height:23px"&gt;图三：&lt;/span&gt;&lt;/div&gt; &lt;div style="line-height:23px"&gt;&lt;span style="line-height:22px; font-size:14px"&gt;&lt;img alt="Searchable之六（Voice Search和Search Suggestions） - hubingforever - 民主与科学" src="http://developer.android.com/images/search/search-suggest-custom.png" style="line-height:25px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; max-width:100%; margin-top:0px; margin-right:10px; margin-bottom:0px; margin-left:0px"&gt;&lt;/span&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/wbr&gt;