我試圖模仿如何搜索是Gmail應用程序,它看起來處理的樣式如下:如圖所示閃爍在搜索查看文本後光標沒有表現出軟鍵盤
上面有一個(藍色)在searchView中的搜索查詢後閃爍光標。
我相應的代碼如下所示:
SearchReslutActivity.class
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setQuery(getIntent().getStringExtra(SearchManager.QUERY), false);
searchView.setIconified(false);
searchView.clearFocus();
return true;
}
菜單/ search_menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/search"
android:title="@string/search_title"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="always" /> </menu>
XML/searchable.xml
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:hint="@string/hint"
android:includeInGlobalSearch="true"
android:inputType="textCapWords"
android:label="@string/app_name"
android:searchSuggestAuthority="com.webaddress.myproject.data.Provider"
android:searchSuggestIntentAction="android.intent.action.VIEW"
android:searchSuggestIntentData="content://com.webaddress.myproject.data.Provider/table"
android:searchSuggestSelection=" ?"
android:searchSuggestThreshold="1" />
上述代碼實現了與gmail應用程序中顯示內容相同的外觀,只是閃爍光標爲。如何在不請求關注searchView
(這又會使軟鍵盤再次彈出)的情況下添加如此閃爍的光標?
謝謝!
[Android Hide Hide Soft Keyboard from EditText while not lose cursor]可能重複(http://stackoverflow.com/questions/13586354/android-hide-soft-keyboard-from-edittext-while-not-losing-cursor ) –
我追蹤了來源。問題來自[this](http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.4_r1/android/support/v7/widget/SearchView.java# 1696)行:'mSearchView.clearFocus();'。如果這個被註釋掉了,閃爍就可以工作了。 – azizbekian
是的,但是當我註釋掉'mSearchView.clearFocus();'鍵盤會再次彈出... – Joni