当前位置: 首页>>代码示例>>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;未经允许,请勿转载。