MenuItem setShowAsAction - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for MenuItem setShowAsAction method.

This code example shows how to use the following methods:setIntent, setShowAsAction, setVisible
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                    | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
 
            // Set the intent to the help menu item, show the help menu item in the overflow 
            // menu, and make it visible. 
            helpMenuItem.setIntent(intent);
            helpMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
            helpMenuItem.setVisible(true);
 
            // return that the help menu item is visible (i.e., true) 
            return true; 
        } 
    } 
 
    /** 
     * Adds two query parameters into the Uri, namely the language code and the version code 
     * of the app's package as gotten via the context. 
     * @return the uri with added query parameters 
     */ 
    private static Uri uriWithAddedParameters(Context context, Uri baseUri) {
8
CodeRank
This code example shows how to use the following methods:setActionView, setIcon, setShowAsAction
    } 
 
    @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
                | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
        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; 
7
CodeRank
This code example shows how to use the following methods:setActionView, setIcon, setShowAsAction
        } 
 
        @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
                    | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
            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. 
            String newFilter = !TextUtils.isEmpty(newText) ? newText : null;
            // Don't do anything if the filter hasn't actually changed. 
            // Prevents restarting the loader when restoring state. 
7
CodeRank
This code example shows how to use the following methods:setChecked, setShowAsAction
This code example shows how to use the following methods:setIntent, setShowAsAction, setVisible
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                    | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
 
            // Set the intent to the help menu item, show the help menu item in the overflow 
            // menu, and make it visible. 
            helpMenuItem.setIntent(intent);
            helpMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
            helpMenuItem.setVisible(true);
 
            // return that the help menu item is visible (i.e., true) 
            return true; 
        } 
    } 
 
    /** 
     * Adds two query parameters into the Uri, namely the language code and the version code 
     * of the app's package as gotten via the context. 
     * @return the uri with added query parameters 
     */ 
    private static Uri uriWithAddedParameters(Context context, Uri baseUri) {
7
CodeRank
This code example shows how to use the following methods:setActionView, setIcon, setShowAsAction
        } 
 
        @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
                    | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
            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. 
            String newFilter = !TextUtils.isEmpty(newText) ? newText : null;
            // Don't do anything if the filter hasn't actually changed. 
            // Prevents restarting the loader when restoring state. 
7
CodeRank
This code example shows how to use the following methods:setIcon, setShowAsAction
        MenuItem actionItem = menu.add("Action Button");
 
        // Items that show as actions should favor the "if room" setting, which will 
        // prevent too many buttons from crowding the bar. Extra items will show in the 
        // overflow area. 
        actionItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
 
        // Items that show as actions are strongly encouraged to use an icon. 
        // These icons are shown without a text description, and therefore should 
        // be sufficiently descriptive on their own. 
        actionItem.setIcon(android.R.drawable.ic_menu_share);
 
        return true; 
    } 
 
    @Override 
    public boolean onOptionsItemSelected(MenuItem item) {
        Toast.makeText(this, "Selected Item: " + item.getTitle(), Toast.LENGTH_SHORT).show();
        return true; 
    } 
6
CodeRank
This code example shows how to use the following methods:setActionView, setIcon, setShowAsAction
        } 
 
        @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);
        } 
 
        @Override public boolean onQueryTextChange(String newText) {
            // Called when the action bar search text has changed.  Since this 
            // is a simple array adapter, we can just have it do the filtering. 
            mCurFilter = !TextUtils.isEmpty(newText) ? newText : null;
            mAdapter.getFilter().filter(mCurFilter);
            return true; 
        } 
 
6
CodeRank
This code example shows how to use the following methods:setActionView, setIcon, setShowAsAction
    } 
     
    @Override 
    public boolean onCreateOptionsMenu(Menu menu) {
    	MenuItem searchItem = menu.add("Search");
    	searchItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    	searchItem.setIcon(android.R.drawable.ic_menu_search);
    	SearchView search = new SearchView(this);
    	searchItem.setActionView(search);
    	 
    	return true; 
    } 
     
    @Override 
    public boolean onOptionsItemSelected(MenuItem item) {
    	return true; 
    } 
     
    private TabSpec newTab(String tag) {
    	 
6
CodeRank
This code example shows how to use the following methods:setShowAsAction
		return false;  // shortcut is not very noticeable 
	} 
 
	@Override 
	public void menuItemSetShowAsAction(MenuItem mi, int flags) {
		mi.setShowAsAction(flags);
	} 
 
	@Override 
	public void lightsOut(Window w, View v, boolean dim) {
		v.setSystemUiVisibility(dim ? View.SYSTEM_UI_FLAG_LOW_PROFILE
				: View.SYSTEM_UI_FLAG_VISIBLE);
	} 
 
	@Override 
	public void addOnMenuVisibilityListener(final OnMenuVisibilityListener l)
	{ 
		actionBar.addOnMenuVisibilityListener(new ActionBar.OnMenuVisibilityListener() {
			@Override public void onMenuVisibilityChanged(boolean isVisible) {
				l.onMenuVisibilityChanged(isVisible);
5
CodeRank

Related MenuItem setShowAsAction Questions & Answers:

setShowAsAction Method Overview
Sets how this item should display in the presence of an Action Bar.
See Code Examples for other Android MenuItem Methods: