Code example for MenuItem

Methods: setActionView, setIcon, setShowAsAction

0
        } 
 
        @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
            // Place an action bar item for searching. 
            MenuItem item = menu.add("Search");
            item.setIcon(android.R.drawable.ic_menu_search);
            item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
            SearchView sv = new SearchView(getActivity());
            sv.setOnQueryTextListener(this);
            item.setActionView(sv);
        } 
 
        public boolean onQueryTextChange(String newText) {
            // Called when the action bar search text has changed.  Update 
            // the search filter, and restart the loader to do a new query 
            // with this filter. 
            mCurFilter = !TextUtils.isEmpty(newText) ? newText : null;
            getLoaderManager().restartLoader(0, null, this);
            return true; 
        }