在我的演示中,我的操作栏上放置了一个搜索视图和一个子菜单,如下所示:@Override public boolean onPrepareOptionsMenu(Menu menu) {
SearchView searchView = new SearchView(getSupportActionBar()
.getThemedContext());
searchView.setQueryHint("Search...");
searchView.setOnQueryTextListener(new OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
if(currentPosition == 0) {
System.out.println("Now search index 0 data...");
}else if(currentPosition == 1) {
System.out.println("Now search index 1 data...");
}
return false;
}
});
menu.add(Menu.NONE, 0, 0, "")
.setIcon(R.drawable.abs__ic_search)
.setActionView(searchView)
.setShowAsAction(
MenuItem.SHOW_AS_ACTION_IF_ROOM
| MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
SubMenu sub = menu.addSubMenu(Menu.NONE, 1, 1, "").setIcon(
R.drawable.abs__ic_menu_moreoverflow_holo_dark);
if(currentPosition == 0) {
sub.add(0, R.style.Theme_Sherlock, 0, "Mail");
sub.add(0, R.style.Theme_Sherlock_Light, 0, "IM");
}else if(currentPosition == 1) {
sub.add(0, R.style.Theme_Sherlock, 0, "City");
sub.add(0, R.style.Theme_Sherlock_Light, 0, "Relocate");
}
sub.getItem().setShowAsAction(
MenuItem.SHOW_AS_ACTION_ALWAYS
| MenuItem.SHOW_AS_ACTION_WITH_TEXT);
return super.onPrepareOptionsMenu(menu);
}
使用 HoloEveryWhere 单击 ActionBar 上的 SearchView 图标时,如何隐藏 SubMenu?