Java Code Examples for android.view.MenuItem.setIcon()

The following are Jave code examples for showing how to use setIcon() of the android.view.MenuItem class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: android-titanium-imagecropper   File: CropImageActivity.java   View Source Code Vote up 6 votes
/** Update the color of a specific menu item to the given color. */
private void updateMenuItemIconColor(Menu menu, int itemId, int color) {
  MenuItem menuItem = menu.findItem(itemId);
  if (menuItem != null) {
    Drawable menuItemIcon = menuItem.getIcon();
    if (menuItemIcon != null) {
      try {
        menuItemIcon.mutate();
        menuItemIcon.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
        menuItem.setIcon(menuItemIcon);
      } catch (Exception e) {
        Log.w("AIC", "Failed to update menu item color", e);
      }
    }
  }
}
 
Example 2
Project: buildAPKsApps   File: SimplyDoActivity.java   View Source Code Vote up 6 votes
@Override
public boolean onPrepareOptionsMenu(Menu menu)
{
    Log.v(L.TAG, "SimplyDoActivity.onPrepareOptionsMenu() called");
    
    menu.clear();
    ViewSwitcher viewSwitch = (ViewSwitcher)findViewById(R.id.ListsItemsSwitcher);
    boolean isItemDisplay = viewSwitch.getDisplayedChild() != 0;
    
    if(isItemDisplay)
    {
        MenuItem deleteInactiveMI = menu.add(Menu.NONE, DELETE_INACTIVE, Menu.NONE, "Delete Inactive");
        deleteInactiveMI.setIcon(android.R.drawable.ic_menu_delete);
    }
    
    MenuItem settingsMI = menu.add(Menu.NONE, SETTINGS, Menu.NONE, "Settings");
    settingsMI.setIcon(android.R.drawable.ic_menu_preferences);
    
    if(isItemDisplay)
    {
        MenuItem sortNowMI = menu.add(Menu.NONE, SORT_NOW, Menu.NONE, "Sort Now");
        sortNowMI.setIcon(android.R.drawable.ic_menu_sort_by_size);
    }
    
    return true;
}
 
Example 3
Project: chat-sdk-android-push-firebase   File: ChatSDKAbstractChatActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onCreateOptionsMenu(Menu menu) {

    if (!inflateMenuItems)
        return super.onCreateOptionsMenu(menu);

    // Adding the add user option only if group chat is enabled.
    if (BDefines.Options.GroupEnabled)
    {
        MenuItem item =
                menu.add(Menu.NONE, R.id.action_chat_sdk_add, 10, getString(R.string.chat_activity_show_users_item_text));
        item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        item.setIcon(R.drawable.ic_plus);
    }

    if (BDefines.Options.ThreadDetailsEnabled)
    {

        MenuItem itemThreadUsers =
            menu.add(Menu.NONE, R.id.action_chat_sdk_thread_details, 10, getString(R.string.chat_activity_show_thread_details));
        
        itemThreadUsers.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        itemThreadUsers.setIcon(android.R.drawable.ic_menu_info_details);
    }
    
    return super.onCreateOptionsMenu(menu);
}
 
Example 4
Project: javaide   File: LogcatActivity.java   View Source Code Vote up 5 votes
private void pauseOrUnpause(MenuItem item) {
    LogReaderAsyncTask currentTask = mTask;

    if (currentTask != null) {
        if (currentTask.isPaused()) {
            currentTask.unpause();
            item.setIcon(R.drawable.ic_pause_white_24dp);
        } else {
            currentTask.pause();
            item.setIcon(R.drawable.ic_play_arrow_white_24dp);
        }
    }
}
 
Example 5
Project: chat-sdk-android-push-firebase   File: ChatcatProfileFragment.java   View Source Code Vote up 5 votes
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);

    MenuItem item =
            menu.add(Menu.NONE, R.id.action_chat_sdk_edit, 13, getString(R.string.action_edit));
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    item.setIcon(R.drawable.ic_edit);
}
 
Example 6
Project: AndroidBackendlessChat   File: ChatSDKAbstractConversationsFragment.java   View Source Code Vote up 5 votes
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    if (!inflateMenuItems)
        return;

    super.onCreateOptionsMenu(menu, inflater);
    MenuItem item =
            menu.add(Menu.NONE, R.id.action_chat_sdk_add, 10, "Add Conversation");
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    item.setIcon(R.drawable.ic_plus);
}
 
Example 7
Project: Camera-Roll-Android-App   File: ExifEditorActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.exif_editor, menu);
    this.menu = menu;

    MenuItem save = menu.findItem(R.id.save);
    save.setVisible(editedItems.size() > 0);
    Drawable d = save.getIcon();
    DrawableCompat.wrap(d);
    DrawableCompat.setTint(d, textColorSecondary);
    DrawableCompat.unwrap(d);
    save.setIcon(d);
    return super.onCreateOptionsMenu(menu);
}
 
Example 8
Project: IslamicLibraryAndroid   File: BookPageFragment.java   View Source Code Vote up 5 votes
private void setBookMarkIcon(MenuItem item) {
    TypedValue typedvalueattr = new TypedValue();
    getActivity().getTheme().resolveAttribute(R.attr.menuBookmarkIcon, typedvalueattr, true);
    StateListDrawable stateListDrawable = (StateListDrawable) getResources().getDrawable(typedvalueattr.resourceId);
    int[] state = {item.isChecked() ? android.R.attr.state_checked : -android.R.attr.state_checked};
    stateListDrawable.setState(state);
    item.setIcon(stateListDrawable.getCurrent());
    item.setTitle(item.isChecked() ? R.string.action_remove_book_mark : R.string.action_add_book_mark);
}
 
Example 9
Project: GitHub   File: RepliesActivity.java   View Source Code Vote up 5 votes
@Override public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        switch (id) {
            case R.id.action_like:
                if(isLiked) {
                    item.setIcon(R.mipmap.ic_toolbar_like_n);
                    mPresenter.delete(topicId);
                    isLiked = false;
                } else {
                    item.setIcon(R.mipmap.ic_toolbar_like_p);
                    RealmLikeBean bean = new RealmLikeBean();
                    bean.setId(topicId);
                    bean.setImage(mTopBean.getMember().getavatar_normal());
//                    bean.setUrl(url);
                    bean.setTitle(mTopBean.getTitle());
                    bean.setType(Constants.TYPE_VTEX);
                    bean.setTime(System.currentTimeMillis());
                    mPresenter.insert(bean);
                    isLiked = true;
                }
                break;
            case R.id.action_copy:
                SystemUtil.copyToClipBoard(mContext, VtexApis.REPLIES_URL + id);
                return true;
            case R.id.action_share:
                ShareUtil.shareText(mContext, VtexApis.REPLIES_URL + id, "分享一篇文章");
        }
        return super.onOptionsItemSelected(item);
    }
 
Example 10
Project: chromium-for-android-56-debug-video   File: AppMenuPropertiesDelegate.java   View Source Code Vote up 5 votes
private void disableEnableMenuItem(
        Menu menu, int id, boolean visible, boolean enabled, boolean managed) {
    for (int i = 0; i < menu.size(); ++i) {
        MenuItem item = menu.getItem(i);
        if (item.getItemId() == id && item.isVisible()) {
            item.setVisible(visible);
            item.setEnabled(enabled);
            if (managed) {
                item.setIcon(ManagedPreferencesUtils.getManagedByEnterpriseIconId());
            } else {
                item.setIcon(null);
            }
        }
    }
}
 
Example 11
Project: Traveler-List   File: MainActivity.java   View Source Code Vote up 5 votes
private void toggle() {
  MenuItem item = menu.findItem(R.id.action_toggle);

  if (isListView) {
    mStaggeredLayoutManager.setSpanCount(2);
    item.setIcon(R.drawable.ic_action_list);
    item.setTitle("Show as list");
    isListView = false;
  } else {
    mStaggeredLayoutManager.setSpanCount(1);
    item.setIcon(R.drawable.ic_action_grid);
    item.setTitle("Show as grid");
    isListView = true;
  }
}
 
Example 12
Project: boohee_v5.6   File: MainActivity.java   View Source Code Vote up 5 votes
private void setMenuColor(boolean firstTab) {
    if (this.menu != null && this.menu.size() > 0) {
        MenuItem messageItem = this.menu.findItem(R.id.action_message);
        if (messageItem == null) {
            return;
        }
        if (firstTab) {
            messageItem.setIcon(R.drawable.a53);
            getSupportActionBar().setHomeAsUpIndicator((int) R.drawable.a56);
            return;
        }
        messageItem.setIcon(R.drawable.a52);
        getSupportActionBar().setHomeAsUpIndicator((int) R.drawable.a55);
    }
}
 
Example 13
Project: appinventor-extensions   File: ReplForm.java   View Source Code Vote up 5 votes
public void addSettingsButton(Menu menu) {
  MenuItem showSettingsItem = menu.add(Menu.NONE, Menu.NONE, 3,
    "Settings").setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
          PhoneStatus.doSettings();
          return true;
        }
      });
  showSettingsItem.setIcon(android.R.drawable.sym_def_app_icon);
}
 
Example 14
Project: MusicX-music-player   File: ToolbarProcessor.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
public static void tintMenu(@NonNull Toolbar toolbar, @Nullable Menu menu, final @ColorInt int color) {
    try {
        final Field field = Toolbar.class.getDeclaredField("mCollapseIcon");
        field.setAccessible(true);
        Drawable collapseIcon = (Drawable) field.get(toolbar);
        if (collapseIcon != null) {
            field.set(toolbar, TintHelper.createTintedDrawable(collapseIcon, color));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    // credits: https://snow.dog/blog/how-to-dynamicaly-change-android-toolbar-icons-color/
    final PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN);
    for (int i = 0; i < toolbar.getChildCount(); i++) {
        final View v = toolbar.getChildAt(i);
        // We can't iterate through the toolbar.getMenu() here, because we need the ActionMenuItemView. ATEActionMenuItemView is overriding the item icon tint color.
        if (v instanceof ActionMenuView) {
            for (int j = 0; j < ((ActionMenuView) v).getChildCount(); j++) {
                final View innerView = ((ActionMenuView) v).getChildAt(j);
                if (innerView instanceof ActionMenuItemView) {
                    int drawablesCount = ((ActionMenuItemView) innerView).getCompoundDrawables().length;
                    for (int k = 0; k < drawablesCount; k++) {
                        if (((ActionMenuItemView) innerView).getCompoundDrawables()[k] != null) {
                            ((ActionMenuItemView) innerView).getCompoundDrawables()[k].setColorFilter(colorFilter);
                        }
                    }
                }
            }
        }
    }

    if (menu == null)
        menu = toolbar.getMenu();
    if (menu != null && menu.size() > 0) {
        for (int i = 0; i < menu.size(); i++) {
            final MenuItem item = menu.getItem(i);
            // We must iterate through the toolbar.getMenu() too, to keep the tint when resuming the paused activity.
            if (item.getIcon() != null) {
                item.setIcon(TintHelper.createTintedDrawable(item.getIcon(), color));
            }
            // Search view theming
            if (item.getActionView() != null && (item.getActionView() instanceof android.widget.SearchView || item.getActionView() instanceof android.support.v7.widget.SearchView)) {
                SearchViewTintUtil.setSearchViewContentColor(item.getActionView(), color);
            }
        }
    }
}
 
Example 15
Project: aos-Video   File: BrowserMoviesBy.java   View Source Code Vote up 5 votes
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
	if (mBrowserAdapter != null && !mBrowserAdapter.isEmpty() && mSortModeSubmenu!=null) {
           // Add the "view mode" item
           MenuItem viewModeMenuItem = menu.add(Browser.MENU_VIEW_MODE_GROUP, Browser.MENU_VIEW_MODE, Menu.NONE, R.string.view_mode);
           viewModeMenuItem.setIcon(R.drawable.ic_menu_view_mode);
           viewModeMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
           mDisplayModeSubmenu.attachMenuItem(viewModeMenuItem);

           mDisplayModeSubmenu.clear();
           mDisplayModeSubmenu.addSubmenuItem(R.drawable.ic_menu_list_mode2, R.string.view_mode_list, 0);
           mDisplayModeSubmenu.addSubmenuItem(R.drawable.ic_menu_poster_mode, R.string.view_mode_grid, 0);
           // no Details view mode here
           mDisplayModeSubmenu.selectSubmenuItem(getSubmenuItemIndex(mViewMode));

		// Add the "sort mode" item
		MenuItem sortMenuItem = menu.add(Browser.MENU_VIEW_MODE_GROUP, Browser.MENU_VIEW_MODE, Menu.NONE, R.string.sort_mode);
		sortMenuItem.setIcon(R.drawable.ic_menu_sort);
		sortMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
		mSortModeSubmenu.attachMenuItem(sortMenuItem);

		
		mSortModeSubmenu.clear();
		addSortOptionsSubmenus(mSortModeSubmenu);

		// Init with the current value
		int initId = sortorder2itemid(mSortOrder);
		if (initId==-1) { // not found
			mSortModeSubmenu.selectSubmenuItem(0);
		}
		else {
			int position = mSortModeSubmenu.getPosition(initId);
			if (position<0) { // not found
			    position=0;
			}
			mSortModeSubmenu.selectSubmenuItem(position);
		}
	}
}
 
Example 16
Project: aos-Video   File: MainActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    boolean ret = super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.cast_menu, menu);
    if(ArchosVideoCastManager.isCastAvailable()) {
        mMediaRouteMenuItem = VideoCastManager.getInstance().addMediaRouterButton(menu, R.id.media_route_menu_item);
        showOverlay();
        VideoCastManager.getInstance().addVideoCastConsumer(new VideoCastConsumerImpl() {
            @Override
            public void onCastAvailabilityChanged(boolean castPresent) {
                if (castPresent) {
                    showOverlay();
                }
            }
        });
    }
    /// /setHomeButtonsetHomeButton();
    MenuItem item = menu.add(MENU_SEARCH_GROUP, MENU_SEARCH_ITEM, Menu.NONE, R.string.search_title);
    item.setIcon(android.R.drawable.ic_menu_search);
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    mSearchView = new SearchView(this);
    mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    item.setActionView(mSearchView);
    mSearchItem = item;
    MenuItem menuItem = menu.add(MENU_SCRAPER_GROUP, MENU_START_AUTO_SCRAPER_ACTIVITY, Menu.NONE,
            R.string.start_auto_scraper_activity);
    menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    MenuItemCompat.setActionProvider(menuItem, mNewVideosActionProvider);
    mNewVideosActionProvider.manageVisibility(menuItem);

    menuItem = menu.add(MENU_PRIVATE_MODE_GROUP, MENU_PRIVATE_MODE_ITEM, Menu.CATEGORY_SECONDARY, R.string.activate_private_mode);
    menuItem.setIcon(R.drawable.ic_menu_private_mode);
    menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);

    return ret;
}
 
Example 17
Project: LayoutSwitch   File: MainActivity.java   View Source Code Vote up 5 votes
private void switchIcon(MenuItem item) {
    if (gridLayoutManager.getSpanCount() == SPAN_COUNT_THREE) {
        item.setIcon(getResources().getDrawable(R.drawable.ic_span_3));
    } else {
        item.setIcon(getResources().getDrawable(R.drawable.ic_span_1));
    }
}
 
Example 18
Project: Bigbang   File: CropImageActivity.java   View Source Code Vote up 5 votes
/**
 * Update the color of a specific menu item to the given color.
 */
private void updateMenuItemIconColor(Menu menu, int itemId, int color) {
    MenuItem menuItem = menu.findItem(itemId);
    if (menuItem != null) {
        Drawable menuItemIcon = menuItem.getIcon();
        if (menuItemIcon != null) {
            try {
                menuItemIcon.mutate();
                menuItemIcon.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
                menuItem.setIcon(menuItemIcon);
            } catch (Exception e) {
            }
        }
    }
}
 
Example 19
Project: leoapp-sources   File: MainActivity.java   View Source Code Vote up 4 votes
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    super.onOptionsItemSelected(item);
    switch (item.getItemId()) {
        case android.R.id.home:
            if (editing)
                onBackPressed();
            else
                getDrawerLayout().openDrawer(GravityCompat.START);
            break;

        case R.id.action_appedit:
            editing = true;

            initFeatureCards();

            findViewById(R.id.card_viewMain).setVisibility(View.GONE);

            getSupportActionBar().setTitle(getString(R.string.cards_customize));
            getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_arrow_left);

            invalidateOptionsMenu();
            break;

        case R.id.action_appedit_done:
            writeCardsToPreferences();
            onBackPressed();
            break;

        case R.id.action_appinfo_quick:
            writeCardsToPreferences();

            boolean b = Utils.getController().getPreferences().getBoolean("pref_key_card_config_quick", false);

            Utils.getController().getPreferences().edit()
                    .putBoolean("pref_key_card_config_quick", !b)
                    .apply();

            initFeatureCards();

            if (!b)
                item.setIcon(R.drawable.ic_format_list_bulleted);
            else
                item.setIcon(R.drawable.ic_widgets);
            break;

        case R.id.action_appedit_add:
            new CardAddDialog(this).show();
            break;

        case R.id.action_request:
            featureRequestDialog = new EditTextDialog(this,
                        getString(R.string.feature_request_title),
                        getString(R.string.feature_request),
                        new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                String emailText = featureRequestDialog.getTextInput();
                                new MailSendTask().execute(emailText);
                                featureRequestDialog.dismiss();
                                Toast.makeText(Utils.getContext(), Utils.getString(R.string.thank_you_feature), Toast.LENGTH_SHORT).show();
                            }
                        });

            featureRequestDialog.show();
            break;

        case R.id.action_settings:
            startActivity(new Intent(getApplicationContext(), PreferenceActivity.class));
            break;

        case R.id.action_help:
            Intent helpIntent = new Intent(MainActivity.this, IntroActivity.class);
            helpIntent.putExtra("no_verification", true);
            MainActivity.this.startActivity(helpIntent);
            break;
    }
    return true;
}
 
Example 20
Project: javaide   File: LogcatActivity.java   View Source Code Vote up 4 votes
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    invalidateDarkOrLightMenuItems(this, menu);

    boolean showingMainLog = (mTask != null);

    MenuItem item = menu.findItem(R.id.menu_expand_all);
    if (mCollapsedMode) {
        item.setIcon(R.drawable.ic_expand_more_white_24dp);
        item.setTitle(R.string.expand_all);
    } else {
        item.setIcon(R.drawable.ic_expand_less_white_24dp);
        item.setTitle(R.string.collapse_all);
    }

    MenuItem clear = menu.findItem(R.id.menu_clear);
    MenuItem pause = menu.findItem(R.id.menu_play_pause);
    clear.setVisible(mCurrentlyOpenLog == null);
    pause.setVisible(mCurrentlyOpenLog == null);

    MenuItem saveLogMenuItem = menu.findItem(R.id.menu_save_log);
    MenuItem saveAsLogMenuItem = menu.findItem(R.id.menu_save_as_log);

    saveLogMenuItem.setEnabled(showingMainLog);
    saveLogMenuItem.setVisible(showingMainLog);

    saveAsLogMenuItem.setEnabled(!showingMainLog);
    saveAsLogMenuItem.setVisible(!showingMainLog);

    boolean recordingInProgress = ServiceHelper.checkIfServiceIsRunning(getApplicationContext(), LogcatRecordingService.class);

    MenuItem recordMenuItem = menu.findItem(R.id.menu_record_log);

    recordMenuItem.setEnabled(!recordingInProgress);
    recordMenuItem.setVisible(!recordingInProgress);

    MenuItem crazyLoggerMenuItem = menu.findItem(R.id.menu_crazy_logger_service);
    crazyLoggerMenuItem.setEnabled(UtilLogger.DEBUG_MODE);
    crazyLoggerMenuItem.setVisible(UtilLogger.DEBUG_MODE);

    MenuItem partialSelectMenuItem = menu.findItem(R.id.menu_partial_select);
    partialSelectMenuItem.setEnabled(!partialSelectMode);
    partialSelectMenuItem.setVisible(!partialSelectMode);

    return super.onPrepareOptionsMenu(menu);
}