@Override public boolean onCreateOptionsMenu(Menu menu) { isGreenStyle = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("style", true); getMenuInflater().inflate(isGreenStyle ? R.menu.menu_new : R.menu.ivt_menu_new, menu); if (!Globals.isPlaying) { MenuItem item = menu.findItem(R.id.action_current_play); item.setVisible(false); // MenuItem item_divider = menu.findItem(R.id.action_divider); // item_divider.setVisible(false); this.invalidateOptionsMenu(); } SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView(); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setOnSearchClickListener( new OnClickListener() { @Override public void onClick(View v) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext.getApplicationContext()); Boolean isImmer = prefs.getBoolean(mContext.getString(R.string.searchview_checkbox_key), true); if (!isImmer) { // Toast.makeText(mContext, "not isImmer", // Toast.LENGTH_LONG).show(); } else { SearchViewDialog dialog = new SearchViewDialog(mContext); dialog.show(); // Toast.makeText(mContext, "isImmer", // Toast.LENGTH_LONG).show(); } } }); return true; }
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); MenuItem searchViewMenuItem = menu.findItem(R.id.action_search); search = (SearchView) searchViewMenuItem.getActionView(); search.setOnQueryTextListener( new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { return false; } @Override public boolean onQueryTextChange(String newText) { if (adapter != null) { Filter filter = adapter.getFilter(); filter.filter(newText); } return true; } }); }