當前位置: 首頁>>代碼示例>>Java>>正文


Java MenuItem.setIcon方法代碼示例

本文整理匯總了Java中android.view.MenuItem.setIcon方法的典型用法代碼示例。如果您正苦於以下問題:Java MenuItem.setIcon方法的具體用法?Java MenuItem.setIcon怎麽用?Java MenuItem.setIcon使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.view.MenuItem的用法示例。


在下文中一共展示了MenuItem.setIcon方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: updateMenuItemIconColor

import android.view.MenuItem; //導入方法依賴的package包/類
/** 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);
      }
    }
  }
}
 
開發者ID:prashantsaini1,項目名稱:android-titanium-imagecropper,代碼行數:17,代碼來源:CropImageActivity.java

示例2: onPrepareOptionsMenu

import android.view.MenuItem; //導入方法依賴的package包/類
@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;
}
 
開發者ID:sdrausty,項目名稱:buildAPKsApps,代碼行數:27,代碼來源:SimplyDoActivity.java

示例3: onCreateOptionsMenu

import android.view.MenuItem; //導入方法依賴的package包/類
@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);
}
 
開發者ID:MobileDev418,項目名稱:chat-sdk-android-push-firebase,代碼行數:28,代碼來源:ChatSDKAbstractChatActivity.java

示例4: pauseOrUnpause

import android.view.MenuItem; //導入方法依賴的package包/類
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);
        }
    }
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:14,代碼來源:LogcatActivity.java

示例5: onCreateOptionsMenu

import android.view.MenuItem; //導入方法依賴的package包/類
@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);
}
 
開發者ID:MobileDev418,項目名稱:chat-sdk-android-push-firebase,代碼行數:10,代碼來源:ChatcatProfileFragment.java

示例6: onCreateOptionsMenu

import android.view.MenuItem; //導入方法依賴的package包/類
@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);
}
 
開發者ID:MobileDev418,項目名稱:AndroidBackendlessChat,代碼行數:12,代碼來源:ChatSDKAbstractConversationsFragment.java

示例7: onCreateOptionsMenu

import android.view.MenuItem; //導入方法依賴的package包/類
@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);
}
 
開發者ID:kollerlukas,項目名稱:Camera-Roll-Android-App,代碼行數:15,代碼來源:ExifEditorActivity.java

示例8: setBookMarkIcon

import android.view.MenuItem; //導入方法依賴的package包/類
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);
}
 
開發者ID:fekracomputers,項目名稱:IslamicLibraryAndroid,代碼行數:10,代碼來源:BookPageFragment.java

示例9: onOptionsItemSelected

import android.view.MenuItem; //導入方法依賴的package包/類
@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);
    }
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:30,代碼來源:RepliesActivity.java

示例10: disableEnableMenuItem

import android.view.MenuItem; //導入方法依賴的package包/類
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);
            }
        }
    }
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:16,代碼來源:AppMenuPropertiesDelegate.java

示例11: toggle

import android.view.MenuItem; //導入方法依賴的package包/類
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;
  }
}
 
開發者ID:anwarcse12028,項目名稱:Traveler-List,代碼行數:16,代碼來源:MainActivity.java

示例12: setMenuColor

import android.view.MenuItem; //導入方法依賴的package包/類
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);
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:16,代碼來源:MainActivity.java

示例13: addSettingsButton

import android.view.MenuItem; //導入方法依賴的package包/類
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);
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:12,代碼來源:ReplForm.java

示例14: tintMenu

import android.view.MenuItem; //導入方法依賴的package包/類
@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);
            }
        }
    }
}
 
開發者ID:RajneeshSingh007,項目名稱:MusicX-music-player,代碼行數:50,代碼來源:ToolbarProcessor.java

示例15: onCreateOptionsMenu

import android.view.MenuItem; //導入方法依賴的package包/類
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);
		}
	}
}
 
開發者ID:archos-sa,項目名稱:aos-Video,代碼行數:39,代碼來源:BrowserMoviesBy.java


注:本文中的android.view.MenuItem.setIcon方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。