我在SearchView
中添加了HomeScreen
。我使用SearchView
进行地点搜索。这是我HomeScreen
的截图:
这是我在onCreateOptionsMenu
方法中的代码:
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
inflater.inflate(R.menu.home, menu);
searchItem = menu.findItem(R.id.menu_item_search_places);
searchItem.setIcon(FontIconDrawable.inflate(getContext(), R.xml.ic_search));
searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
searchView.setOnSuggestionListener(this);
searchView.setOnQueryTextListener(this);
placesSearchAdapter = new PlacesSearchAdapter(this.getContext());
searchView.setSuggestionsAdapter(placesSearchAdapter);
searchView.setMaxWidth(750);
MenuItemCompat.setOnActionExpandListener(searchItem, new MenuItemCompat.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
return true;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
corLDriveInfoContainer.setVisibility(View.GONE);
fabDrivingDirection.setVisibility(View.VISIBLE);
mapView.deleteAllAnnotationsAndCustomPOIs();
return true;
}
});
}
当我点击SearchView
时,这是我SearchIcon
。
这是我的SearchView
结果:
我有FabButton
来推动所选位置。
但是,我的问题是,当我按下按钮时,如何从View C
返回View D
?
答案 0 :(得分:1)
您应该像这样覆盖活动中的onBackPressed
方法
@Override
public void onBackPressed() {
super.onBackPressed();
//change your View from D to C using the same code you used to go to D from C
}
答案 1 :(得分:1)
我将其包含在onBackPress
方法中解决我的问题:
@Override
public void onBackPressed() {
searchItem.expandActionView();
searchView.setQuery("", false);
searchView.clearFocus();
super.onBackPressed();
}