Java Code Examples for android.view.MenuItem#setShowAsAction()

The following examples show how to use android.view.MenuItem#setShowAsAction() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    if (!UserDictionarySettings.IS_SHORTCUT_API_SUPPORTED) {
        final Locale systemLocale = getResources().getConfiguration().locale;
        if (!TextUtils.isEmpty(mLocale) && !mLocale.equals(systemLocale.toString())) {
            // Hide the add button for ICS because it doesn't support specifying a locale
            // for an entry. This new "locale"-aware API has been added in conjunction
            // with the shortcut API.
            return;
        }
    }
    MenuItem actionItem =
            menu.add(0, OPTIONS_MENU_ADD, 0, R.string.user_dict_settings_add_menu_title)
            .setIcon(R.drawable.ic_menu_add);
    actionItem.setShowAsAction(
            MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
}
 
Example 2
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.activity_add_edit_camera, menu);

    MenuItem supportMenuItem = menu.findItem(R.id.menu_action_support);
    if (supportMenuItem != null) {
        LinearLayout menuLayout = (LinearLayout) LayoutInflater.from(this)
                .inflate(R.layout.menu_support_lowercase, null);
        supportMenuItem.setActionView(menuLayout);
        supportMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

        menuLayout.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intercom.client().displayConversationsList();
            }
        });
    }

    return true;
}
 
Example 3
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    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);
    return true;
}
 
Example 4
Source Project: react-native-GPay   File: ReactToolbar.java    License: MIT License 6 votes vote down vote up
void setActions(@Nullable ReadableArray actions) {
  Menu menu = getMenu();
  menu.clear();
  mActionsHolder.clear();
  if (actions != null) {
    for (int i = 0; i < actions.size(); i++) {
      ReadableMap action = actions.getMap(i);

      MenuItem item = menu.add(Menu.NONE, Menu.NONE, i, action.getString(PROP_ACTION_TITLE));

      if (action.hasKey(PROP_ACTION_ICON)) {
        setMenuItemIcon(item, action.getMap(PROP_ACTION_ICON));
      }

      int showAsAction = action.hasKey(PROP_ACTION_SHOW)
          ? action.getInt(PROP_ACTION_SHOW)
          : MenuItem.SHOW_AS_ACTION_NEVER;
      if (action.hasKey(PROP_ACTION_SHOW_WITH_TEXT) &&
          action.getBoolean(PROP_ACTION_SHOW_WITH_TEXT)) {
        showAsAction = showAsAction | MenuItem.SHOW_AS_ACTION_WITH_TEXT;
      }
      item.setShowAsAction(showAsAction);
    }
  }
}
 
Example 5
Source Project: OpenXiaomiScale   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu)
{
	MenuItem item = menu.findItem(R.id.menu_item_share);

	if (isShareIconEnabled) {
		item.setEnabled(true);
		item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
	} else {
		// disabled
		item.setEnabled(false);
		item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
	}

	return super.onPrepareOptionsMenu(menu);
}
 
Example 6
@SuppressLint("NewApi")
@Override
public boolean createSelectionActionModeMenuItem(MenuItem convert) {
	convert.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
	
	return true;
}
 
Example 7
Source Project: abelana   File: PicturesFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    MenuItem refreshMenu = menu.add(R.string.action_refresh);
    refreshMenu.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS
            | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
    refreshMenu.setOnMenuItemClickListener(this);
    super.onCreateOptionsMenu(menu, inflater);
}
 
Example 8
Source Project: bitcoinpos   File: ItemFragment.java    License: MIT License 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_main, menu);
    MenuItem item = menu.add(Menu.NONE, R.id.add_item, 500, R.string.add_item);
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    item.setIcon(R.drawable.ic_plus_white_24dp);
}
 
Example 9
Source Project: commcare-android   File: ViewUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void addItemToActionBar(Menu menu, int menuId, int menuGroupId, String title,
                                      @DrawableRes int drawableResource) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        MenuItem item = menu.add(menuGroupId, menuId, menuId, title);
        item.setIcon(drawableResource);
        item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    }
}
 
Example 10
@Override
public boolean onCreateOptionsMenu(Menu menu) {

	final MenuItem send = menu.add(R.string.comment_reply_send);
	send.setIcon(R.drawable.ic_action_send_dark);
	send.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

	menu.add(R.string.comment_reply_preview);

	return true;
}
 
Example 11
@Override
public boolean onCreateOptionsMenu(Menu menu) {
	if (isMultipleSelection) {
		MenuItem menuitem = menu.add(Menu.NONE, DONE_MENU, Menu.NONE, Defaults.DONE_BTN_TITLE);
        menuitem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
	}

    return true;
}
 
Example 12
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    final MenuItem menuItem = menu.add(getString(R.string.menu_close));
    menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(final MenuItem item) {
            if (item.getTitle().equals(menuItem.getTitle())) {
                getActivity().finish();
            }
            return true;
        }
    });
}
 
Example 13
@SuppressLint("NewApi")
@Override
public boolean createSelectionActionModeMenuItem(MenuItem convert) {
	convert.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
	
	return true;
}
 
Example 14
@Override
public boolean onCreateOptionsMenu(Menu menu) {

	final MenuItem send = menu.add(R.string.comment_reply_send);
	send.setIcon(R.drawable.ic_action_send_dark);
	send.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

	menu.add(R.string.comment_reply_preview);

	return true;
}
 
Example 15
/**
 * This method is called for creating action menu.
 * Adds the import BPC developer button in debug mode
 *
 * @param menu the menu to be created
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu, menu);

    if (BuildConfig.DEBUG) {
        MenuItem item = menu.add("Import BPC");
        item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    }

    return super.onCreateOptionsMenu(menu);
}
 
Example 16
Source Project: V.FlyoutTest   File: CursorFragment.java    License: MIT License 5 votes vote down vote up
@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);
}
 
Example 17
@Override
public boolean onCreateOptionsMenu(Menu menu) {

	final MenuItem send = menu.add(R.string.comment_reply_send);
	send.setIcon(R.drawable.ic_action_send_dark);
	send.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

	menu.add(R.string.comment_reply_preview);

	return true;
}
 
Example 18
public void setShowAsActionIfRoomWithText(MenuItem menuitem)
{
       menuitem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM|MenuItem.SHOW_AS_ACTION_WITH_TEXT);
}
 
Example 19
public static void setShowAsAction(MenuItem item, int actionEnum) {
    item.setShowAsAction(actionEnum);
}
 
Example 20
@SuppressLint("AlwaysShowAction")
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    boolean ret = super.onPrepareOptionsMenu(menu);

    MenuItem menuItem;

    //menuItem = menu.findItem(R.id.menu_import_export);
    //menuItem.setTitle(getResources().getString(R.string.menu_import_export) + "  >");

    // change global events run/stop menu item title
    menuItem = menu.findItem(R.id.menu_run_stop_events);
    if (menuItem != null)
    {
        if (Event.getGlobalEventsRunning())
        {
            menuItem.setTitle(R.string.menu_stop_events);
            menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
        }
        else
        {
            menuItem.setTitle(R.string.menu_run_events);
            menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
        }
    }

    menuItem = menu.findItem(R.id.menu_restart_events);
    if (menuItem != null)
    {
        menuItem.setVisible(Event.getGlobalEventsRunning());
        menuItem.setEnabled(PPApplication.getApplicationStarted(true));
    }

    menuItem = menu.findItem(R.id.menu_dark_theme);
    if (menuItem != null)
    {
        String appTheme = ApplicationPreferences.applicationTheme(getApplicationContext(), false);
        if (!appTheme.equals("night_mode")) {
            menuItem.setVisible(true);
            if (appTheme.equals("dark"))
                menuItem.setTitle(R.string.menu_dark_theme_off);
            else
                menuItem.setTitle(R.string.menu_dark_theme_on);
        }
        else
            menuItem.setVisible(false);
    }

    menuItem = menu.findItem(R.id.menu_email_debug_logs_to_author);
    if (menuItem != null)
    {
        //noinspection ConstantConditions
        menuItem.setVisible(PPApplication.logIntoFile || PPApplication.crashIntoFile);
    }

    menuItem = menu.findItem(R.id.menu_test_crash);
    if (menuItem != null)
    {
        menuItem.setVisible(DebugVersion.enabled);
    }
    menuItem = menu.findItem(R.id.menu_test_nonFatal);
    if (menuItem != null)
    {
        menuItem.setVisible(DebugVersion.enabled);
    }

    menuItem = menu.findItem(R.id.menu_import);
    if (menuItem != null) {
        File sd = Environment.getExternalStorageDirectory();
        File exportedDB = new File(sd, PPApplication.EXPORT_PATH + "/" + DatabaseHandler.EXPORT_DBFILENAME);
        boolean dbExists = exportedDB.exists();
        File exportedAppPreferences = new File(sd, PPApplication.EXPORT_PATH + "/" + GlobalGUIRoutines.EXPORT_APP_PREF_FILENAME);
        boolean appPreferencesExists = exportedAppPreferences.exists();
        menuItem.setEnabled(dbExists && appPreferencesExists);
    }

    onNextLayout(editorToolbar, new Runnable() {
        @Override
        public void run() {
            showTargetHelps();
        }
    });

    return ret;
}