Example usage for android.view MenuItem SHOW_AS_ACTION_WITH_TEXT

List of usage examples for android.view MenuItem SHOW_AS_ACTION_WITH_TEXT

Introduction

In this page you can find the example usage for android.view MenuItem SHOW_AS_ACTION_WITH_TEXT.

Prototype

int SHOW_AS_ACTION_WITH_TEXT

To view the source code for android.view MenuItem SHOW_AS_ACTION_WITH_TEXT.

Click Source Link

Document

When this item is in the action bar, always show it with a text label even if it also has an icon specified.

Usage

From source file:com.simadanesh.isatis.ScreenSlideActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    try {//from w ww.j  a va 2  s  . c  o  m
        getMenuInflater().inflate(R.menu.activity_screen_slide, menu);

        menu.findItem(R.id.action_previous).setEnabled(mPager.getCurrentItem() > 0);

        // Add either a "next" or "finish" button to the action bar, depending on which page
        // is currently selected.
        MenuItem item = menu.add(Menu.NONE, R.id.action_next, Menu.NONE,
                (mPager.getCurrentItem() == mPagerAdapter.getCount() - 1) ? R.string.action_finish
                        : R.string.action_next);
        item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
        item.setIcon(R.drawable.ic_menu_forward);

        MenuItem stepItem = menu.add(Menu.NONE, R.id.action_step_ten, Menu.NONE,
                step10 ? R.string.action_step_ten : R.string.action_step_one);

        stepItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

        MenuItem turn_on_flash_Item = menu.add(Menu.NONE, R.id.action_turn_on_flash, Menu.NONE,
                R.string.action_turn_on_light);

        turn_on_flash_Item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
        turn_on_flash_Item.setIcon(R.drawable.ic_menu_flashlight);

        MenuItem filter_Item = menu.add(Menu.NONE, R.id.action_filter, Menu.NONE, R.string.filter);

        filter_Item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
        filter_Item.setIcon(R.drawable.filter);

        MenuItem search_Item = menu.add(Menu.NONE, R.id.action_search, Menu.NONE, R.string.search);

        search_Item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

        MenuItem addCustomer_Item = menu.add(Menu.NONE, R.id.action_new_customer, Menu.NONE,
                R.string.new_customer);

        addCustomer_Item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

        setTitle();
        progressbar.setProgress(mPager.getCurrentItem() + 1);
        progressbar.setMax(mPagerAdapter.getCount());
        final Handler handler = new Handler();
        progressbar.setVisibility(View.VISIBLE);
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                callCount--;
                if (callCount <= 0) {
                    progressbar.setVisibility(View.GONE);
                }
            }
        }, 3000);
        callCount++;
    } catch (Exception ex) {
        ex.toString();
    }
    return true;
}

From source file:org.openintents.shopping.ui.ShoppingActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    /*//  www  .  j  av  a  2  s . c  om
     * int MENU_ACTION_WITH_TEXT=0;
     * 
     * //Temp- for backward compatibility with OS 3 features
     * 
     * if(!usingListSpinner()){ try{ //setting the value equivalent to
     * desired expression
     * //MenuItem.SHOW_AS_ACTION_IF_ROOM|MenuItem.SHOW_AS_ACTION_WITH_TEXT
     * java.lang.reflect.Field
     * field=MenuItem.class.getDeclaredField("SHOW_AS_ACTION_IF_ROOM");
     * MENU_ACTION_WITH_TEXT=field.getInt(MenuItem.class);
     * field=MenuItem.class.getDeclaredField("SHOW_AS_ACTION_WITH_TEXT");
     * MENU_ACTION_WITH_TEXT|=field.getInt(MenuItem.class); }catch(Exception
     * e){ //reset value irrespective of cause MENU_ACTION_WITH_TEXT=0; }
     * 
     * }
     */

    // Add menu option for auto adding items from string array in intent
    // extra if they exist
    if (mExtraItems != null) {
        menu.add(0, MENU_INSERT_FROM_EXTRAS, 0, R.string.menu_auto_add)
                .setIcon(android.R.drawable.ic_menu_upload);
    }

    MenuItem item = null;

    View searchView = mItemsView.getSearchView();
    if (searchView != null) {
        item = menu.add(0, MENU_SEARCH_ADD, 0, R.string.menu_search_add);
        MenuItemCompat.setActionView(item, searchView);
        MenuItemCompat.setShowAsAction(item, MenuItem.SHOW_AS_ACTION_ALWAYS);
    }
    mAddPanel.setVisibility(searchView == null ? View.VISIBLE : View.GONE);

    item = menu.add(0, MENU_SORT_LIST, 0, R.string.menu_sort_list)
            .setIcon(android.R.drawable.ic_menu_sort_alphabetically);
    MenuItemCompat.setShowAsAction(item, MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
    if (mListSortActionProvider == null) {
        mListSortActionProvider = new ListSortActionProvider(this);
    }
    MenuItemCompat.setActionProvider(item, mListSortActionProvider);

    // Standard menu

    // tentatively moved "new list" to drawer
    //item = menu.add(0, MENU_NEW_LIST, 0, R.string.new_list)
    //      .setIcon(R.drawable.ic_menu_add_list).setShortcut('0', 'n');
    // MenuCompat.setShowAsAction(item, MenuItem.SHOW_AS_ACTION_IF_ROOM);

    item = menu.add(0, MENU_CLEAN_UP_LIST, 0, R.string.clean_up_list).setIcon(R.drawable.ic_menu_cleanup)
            .setShortcut('1', 'c');
    MenuItemCompat.setShowAsAction(item, MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

    menu.add(0, MENU_PICK_ITEMS, 0, R.string.menu_pick_items).setIcon(android.R.drawable.ic_menu_add)
            .setShortcut('2', 'p').
            // tentatively replaced by buttons in drawer.
            setVisible(false);

    /*
     * menu.add(0, MENU_SHARE, 0, R.string.share)
     * .setIcon(R.drawable.contact_share001a) .setShortcut('4', 's');
     */

    menu.add(0, MENU_THEME, 0, R.string.theme).setIcon(android.R.drawable.ic_menu_manage).setShortcut('3', 't');

    menu.add(0, MENU_PREFERENCES, 0, R.string.preferences).setIcon(android.R.drawable.ic_menu_preferences)
            .setShortcut('4', 'p');

    menu.add(0, MENU_RENAME_LIST, 0, R.string.rename_list).setIcon(android.R.drawable.ic_menu_edit)
            .setShortcut('5', 'r');

    menu.add(0, MENU_DELETE_LIST, 0, R.string.delete_list).setIcon(android.R.drawable.ic_menu_delete);

    menu.add(0, MENU_SEND, 0, R.string.send).setIcon(android.R.drawable.ic_menu_send).setShortcut('7', 's');

    if (addLocationAlertPossible()) {
        menu.add(0, MENU_ADD_LOCATION_ALERT, 0, R.string.shopping_add_alert)
                .setIcon(android.R.drawable.ic_menu_mylocation).setShortcut('8', 'l');
    }

    menu.add(0, MENU_MARK_ALL_ITEMS, 0, R.string.mark_all_items).setIcon(android.R.drawable.ic_menu_agenda)
            .setShortcut('9', 'm');

    menu.add(0, MENU_UNMARK_ALL_ITEMS, 0, R.string.unmark_all_items);

    menu.add(0, MENU_SYNC_WEAR, 0, R.string.sync_wear);

    // Add distribution menu items last.
    mDistribution.onCreateOptionsMenu(menu);

    // NOTE:
    // Dynamically added menu items are included in onPrepareOptionsMenu()
    // instead of here!
    // (Explanation see there.)

    return true;
}