前言
變態問題常有,今年特別多,,, - - # 今天遇到的這個非處理不可,不然沒法在HTC One S使用SearchView,其軟鍵盤不支持action設置。
聲明
歡迎轉載,但請保留文章原始出處:)
博客園:http://www.cnblogs.com
農民伯伯: http://www.cnblogs.com/over140/
正文
問題設備:
HTC One S
searchable.xml
<
searchable
xmlns:android
="http://schemas.android.com/apk/res/android"
android:label ="@string/search_label"
android:hint ="@string/search_hint"
android:voiceSearchMode ="showVoiceSearchButton|launchRecognizer"
android:imeOptions ="actionSearch"
android:searchSuggestAuthority ="com.xxx.provider.searchsuggestion"
android:searchSuggestSelection =" ? " />
android:label ="@string/search_label"
android:hint ="@string/search_hint"
android:voiceSearchMode ="showVoiceSearchButton|launchRecognizer"
android:imeOptions ="actionSearch"
android:searchSuggestAuthority ="com.xxx.provider.searchsuggestion"
android:searchSuggestSelection =" ? " />
解決辦法:
SearchView有一個setSubmitButtonEnabled方法,設置為true即可,搜索框不為空就會顯示。效果如下圖:
在onCreateOptionsMenu中inflate后調用,記得判斷API Level。