gpt4 book ai didi

选择建议后 Android Searchview 禁用全屏不起作用

转载 作者:行者123 更新时间:2023-11-29 20:00:03 25 4
gpt4 key购买 nike

情况

我的工具栏中有一个 SearchView,可在用户输入搜索时向其显示建议。最初,在横向模式下,显示的软键盘和可见的搜索 View 一切正常。但是,在用户选择一个建议并尝试进行第二次搜索后,搜索界面现在处于全屏状态,搜索 View 被覆盖,无法看到建议。

问题

无论使用多少次搜索功能,如何始终不全屏?

我尝试过的事情

ImeOptions - flagNoFullscreen, flagNoExtractUi

代码

主要 fragment

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.favorites, menu);

MenuItem toggleItem = menu.findItem(R.id.toggle_shake);
setUpToggleShake(toggleItem);

MenuItem singleSearchItem = menu.findItem(R.id.search_restaurant);
setUpSingleSearch(menu, singleSearchItem);
}

private void setUpSingleSearch(final Menu menu, final MenuItem singleSearchItem) {
searchView = (SearchView) MenuItemCompat.getActionView(singleSearchItem);
searchView.setQueryHint("Search Restaurant");
searchView.setMaxWidth(10000);
searchView.setImeOptions(searchView.getImeOptions() | EditorInfo.IME_FLAG_NO_FULLSCREEN |
EditorInfo.IME_FLAG_NO_EXTRACT_UI);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}

@Override
public boolean onQueryTextChange(String newText) {
displaySuggestions(newText);
return false;
}
});
searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() {
@Override
public boolean onSuggestionSelect(int position) {
return false;
}

@Override
public boolean onSuggestionClick(int position) {
MatrixCursor cursor = (MatrixCursor)(searchView.getSuggestionsAdapter()
.getCursor());
if (cursor.moveToPosition(position)) {
String restaurantId = cursor.getString(cursor.getColumnIndex(
RestaurantTable.Cols.ID));
mFavoritesRestaurantListAdapter.setSingleSearchRestaurant(restaurantId);
mFavoritesRestaurantListAdapter.onSingleSearch();
}
searchView.clearFocus();
searchView.onActionViewCollapsed();
setItemsVisibility(menu, singleSearchItem, true);

return false;
}
});
searchView.setOnSearchClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setItemsVisibility(menu, singleSearchItem, false);
searchView.setFocusable(true);
searchView.requestFocus();
searchView.requestFocusFromTouch();
}
});
searchView.setOnCloseListener(new SearchView.OnCloseListener() {
@Override
public boolean onClose() {
setItemsVisibility(menu, singleSearchItem, true);
searchView.clearFocus();
return false;
}
});
final AutoCompleteTextView searchAutoCompleteTextView = (AutoCompleteTextView) searchView
.findViewById(R.id.search_src_text);
searchAutoCompleteTextView.setThreshold(1);
}

最佳答案

问题似乎是对 SearchView 的 onActionViewCollapsed 的调用。我通过在 menu.xml 中添加 collapseActionView 来解决此问题。

<item
android:id="@+id/search_restaurant"
android:title="Search"
android:icon="@drawable/search"
android:orderInCategory="2"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="always|collapseActionView"/>

然后移除searchview.onActionViewCollapsed。改为添加 menuItem.collapseActionView。

searchView.clearFocus();
//searchView.onActionViewCollapsed();
menuItem.collapseActionView(); //Added this
setItemsVisibility(menu, singleSearchItem, true);

关于选择建议后 Android Searchview 禁用全屏不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36390071/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com