Searchable配置文件详解(下)

文章来源:http://developer.android.com/guide/topics/search/searchable-config.html
<actionkey>的一些属性
<actionkey>主要用于定义在键入搜索关键字时或suggestion被focus时,按下哪个键,系统将把什么ACTION_MSG携带 ACTION_SEARCH  intent发送到你的 searchable activity
比如对于Contacts,我们可能希望在一个suggestion被focus的时候,按下设备上call键,就直接向与被focus中的suggesion所对于的人拨打电话。这里的intent会直接通过component名直接传到你的searchable activity.
并不是每个设备都实现了Android定义的所有键,当然也不是所有的键可以被override.比如home,当它被按下的,系统应该总是回到home界面。一定不要把任何要用于输入的键设置为action key.这就大大限制了可以做action key的键,一般如果没硬键盘,就只有call或menu键。还要注意的是action key一般不发现的,所以你不应该把他们作为核心用户功能来提供。
你必须设置android:keycode属性和其他的任一属性。
android:keycode
String . (必须) A key code from  KeyEvent  that represents the action key you wish to respond to (for example "KEYCODE_CALL" ). This is added to the  ACTION_SEARCH  intent that is passed to your searchable activity. To examine the key code, use  getIntExtra(SearchManager.ACTION_KEY) . Not all keys are supported for a search action, as many of them are used for typing, navigation, or system functions.
它用于定义在键入搜索关键字时或suggestion被focus时,哪个键被按下,系统向你的searchable activity发送 ACTION_SEARCH intent。
android:queryActionMsg
String. An action message to be sent if the action key is pressed while the user is entering query text. This is added to the  ACTION_SEARCH intent that the system passes to your searchable activity. To examine the string, use  getStringExtra(SearchManager.ACTION_MSG). 它用于定义在键入搜索关键字时,某个键被按下时,系统向你的searchable activity发送 ACTION_SEARCH intent 的附加信息,该信息可以通过 getStringExtra(SearchManager.ACTION_MSG)来提取
android:suggestActionMsg
String. An action message to be sent if the action key is pressed while a suggestion is in focus. This is added to the intent that that the system passes to your searchable activity (using the action you've defined for the suggestion). To examine the string, use getStringExtra(SearchManager.ACTION_MSG). This should only be used if all your suggestions support this action key. If not all suggestions can handle the same action key, then you must instead use the following android:suggestActionMsgColumn attribute. 它用于定义某个suggestion被focus时,某个键被按下时,系统向你的searchable activity发送 ACTION_SEARCH intent 的附加信息,该信息可以通过 getStringExtra(SearchManager.ACTION_MSG)来提取
android:suggestActionMsgColumn
    String. The name of the column in your content provider that defines the action message for this action key, which is to be sent if the user presses the action key while a suggestion is in focus. This attribute lets you control the action key on a suggestion-by-suggestion basis, because, instead of using the android:suggestActionMsg attribute to define the action message for all suggestions, each entry in your content provider provides its own action message. 
First, you must define a column in your content provider for each suggestion to provide an action message, then provide the name of that column in this attribute. The system looks at your suggestion cursor, using the string provided here to select your action message column, and then select the action message string from the Cursor. That string is added to the intent that the system passes to your searchable activity (using the action you've defined for suggestions). To examine the string, use getStringExtra(SearchManager.ACTION_MSG). If the data does not exist for the selected suggestion, the action key is ignored.
当某个suggestion被focus时,某个键被按下时,系统向你的searchable activity发送 ACTION_SEARCH intent 的附加信息,该属性定义了附加信息来源于suggestion Cursor的哪一列, 该附加信息可以通 getStringExtra(SearchManager.ACTION_MSG)来提取。
注意 android:suggestActionMsg android:suggestActionMsgColumn好像同时使用,就只有后者才有意义
示例 res/xml/searchable.xml
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
   
android:label="@string/search_label"
   
android:hint="@string/search_hint"
   
android:searchSuggestAuthority="dictionary"
   
android:searchSuggestIntentAction="android.intent.action.VIEW"
   
android:includeInGlobalSearch="true"
   
android:searchSettingsDescription="@string/settings_description" >
</searchable>

你可能感兴趣的:(android,String,System,action,Dictionary,encoding)