在android應用中,為了有良好的用戶體驗,需要提供搜索功能,在android中通過系統提供的 SearchManager來進行實現,
對Search的訪問只能通過系統提供的context.getSystemService(Context.SEARCH_SERVICE)來進行實現,不能對SearchManager進行初始化
需要在res/xml下面添加一個配置文件
核心為
<serchable
xmls:android:"......"
android:hint="@string/searchHint"
android:label="@string/searchLable"
android:searchMode="ShowSearchLabelAsBadge"
android:searchSuggestAuthority="com.anroid.coding.SearchSuggestionSampleProvider"
android:searchSuggestSelection="?">
</serchable>
<!-- Label 為搜索框上面的文本,hint為搜索框里面的提示文本
-->
android:hint="@string/searchHint"
android:label="@string/searchLabel"
<!-- 語音搜索配置
android:voiceSearchMode:="showVoiceSearchButton|launchRecognizer"
android:voiceLanguageModel="free_from"
android:voicePromptText="@string/search_invoke"
-->
<!-- 配置搜索建議
searchSuggesteAuthority的值必須是繼承自SearchRecentSuggestionsProvider的完整路徑名
android:searchSuggesterAuthority="com.anroid.coding.SearchSuggestionSampleProvider"
android:searchSuggestSelection="?"
-->