android.view.MenuItem.setIcon()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(124)

本文整理了Java中android.view.MenuItem.setIcon()方法的一些代码示例,展示了MenuItem.setIcon()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MenuItem.setIcon()方法的具体详情如下:
包路径:android.view.MenuItem
类名称:MenuItem
方法名:setIcon

暂无

代码示例

代码示例来源:origin: stackoverflow.com

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
  MenuItem switchButton = menu.findItem(R.id.SwitchSearchOption);     
  if(searchScriptDisplayed){
    switchButton.setIcon(R.drawable.menu_precedent);
  }else{
    switchButton.setIcon(R.drawable.icon_search);
  }
  return super.onPrepareOptionsMenu(menu);

}

代码示例来源:origin: TeamNewPipe/NewPipe

private void updateBookmarkButtons() {
    if (playlistBookmarkButton == null || activity == null) return;

    final int iconAttr = playlistEntity == null ?
        R.attr.ic_playlist_add : R.attr.ic_playlist_check;

    final int titleRes = playlistEntity == null ?
        R.string.bookmark_playlist : R.string.unbookmark_playlist;

    playlistBookmarkButton.setIcon(ThemeHelper.resolveResourceIdFromAttr(activity, iconAttr));
    playlistBookmarkButton.setTitle(titleRes);
  }
}

代码示例来源:origin: stackoverflow.com

MenuItem favoriteItem = menu.findItem(R.id.action_favorite);
Drawable newIcon = (Drawable)favoriteItem.getIcon();
newIcon.mutate().setColorFilter(Color.argb(255, 200, 200, 200), PorterDuff.Mode.SRC_IN);
favoriteItem.setIcon(newIcon);

代码示例来源:origin: 4thline/cling

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  menu.add(0, 0, 0, R.string.switchRouter).setIcon(android.R.drawable.ic_menu_revert);
  menu.add(0, 1, 0, R.string.toggleDebugLogging).setIcon(android.R.drawable.ic_menu_info_details);
  return true;
}

代码示例来源:origin: alexvasilkov/GestureViews

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  if (infoTextId != 0) {
    MenuItem item = menu.add(Menu.NONE, R.id.menu_info, Menu.NONE, R.string.menu_info);
    item.setIcon(R.drawable.ic_info_outline_white_24dp);
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
  }
  return true;
}

代码示例来源:origin: mikepenz/MaterialDrawer

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  MenuInflater inflater = getMenuInflater();
  if (SystemUtils.getScreenOrientation() == Configuration.ORIENTATION_LANDSCAPE) {
    inflater.inflate(R.menu.embedded, menu);
    menu.findItem(R.id.menu_1).setIcon(new IconicsDrawable(this, GoogleMaterial.Icon.gmd_sort).color(Color.WHITE).actionBar());
  }
  return true;
}

代码示例来源:origin: mikepenz/FastAdapter

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.sort, menu);
  menu.findItem(R.id.item_sort_random).setIcon(new IconicsDrawable(this, MaterialDesignIconic.Icon.gmi_wrap_text).color(Color.BLACK).actionBar());
  menu.findItem(R.id.item_sort_asc).setIcon(new IconicsDrawable(this, MaterialDesignIconic.Icon.gmi_sort_asc).color(Color.BLACK).actionBar());
  menu.findItem(R.id.item_sort_desc).setIcon(new IconicsDrawable(this, MaterialDesignIconic.Icon.gmi_sort_desc).color(Color.BLACK).actionBar());
  return true;
}

代码示例来源:origin: mikepenz/FastAdapter

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.refresh, menu);
  menu.findItem(R.id.item_refresh).setIcon(new IconicsDrawable(this, MaterialDesignIconic.Icon.gmi_refresh).color(Color.BLACK).actionBar());
  menu.findItem(R.id.item_refresh_async).setIcon(new IconicsDrawable(this, MaterialDesignIconic.Icon.gmi_refresh_sync).color(Color.BLACK).actionBar());
  return true;
}

代码示例来源:origin: hidroh/materialistic

@SuppressWarnings("unused")
  public void setIcon(MenuItem item, @DrawableRes int icon) {
    item.setIcon(icon);
    Drawable drawable = item.getIcon();
    drawable = DrawableCompat.wrap(drawable);
    DrawableCompat.setTint(drawable, mTextColorPrimary);
  }
}

代码示例来源:origin: mikepenz/FastAdapter

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.menu, menu);
  menu.findItem(R.id.item_add).setIcon(new IconicsDrawable(this, MaterialDesignIconic.Icon.gmi_plus_square).color(Color.BLACK).actionBar());
  menu.findItem(R.id.item_delete).setIcon(new IconicsDrawable(this, MaterialDesignIconic.Icon.gmi_minus_square).color(Color.BLACK).actionBar());
  menu.findItem(R.id.item_change).setIcon(new IconicsDrawable(this, MaterialDesignIconic.Icon.gmi_settings_square).color(Color.BLACK).actionBar());
  menu.findItem(R.id.item_move).setIcon(new IconicsDrawable(this, MaterialDesignIconic.Icon.gmi_format_valign_bottom).color(Color.BLACK).actionBar());
  return true;
}

代码示例来源:origin: cSploit/android

public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
  int i = mTargetAdapter.getSelectedCount();
  mode.setTitle(i + " " + getString((i > 1 ? R.string.targets_selected : R.string.target_selected)));
  MenuItem item = menu.findItem(R.id.multi_action);
  if (item != null)
    item.setIcon((i > 1 ? android.R.drawable.ic_dialog_dialer : android.R.drawable.ic_menu_edit));
  return false;
}

代码示例来源:origin: mikepenz/FastAdapter

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.menu_add, menu);
  menu.findItem(R.id.item_add).setIcon(new IconicsDrawable(this, MaterialDesignIconic.Icon.gmi_plus_square).color(Color.BLACK).actionBar());
  return true;
}

代码示例来源:origin: pockethub/PocketHub

private void setUpNavigationMenu() {
  MenuItem organizationContainer = navigationView.getMenu().findItem(R.id.navigation_organizations);
  if (organizationContainer.hasSubMenu()) {
    SubMenu organizationsMenu = organizationContainer.getSubMenu();
    for (int i = 1; i < orgs.size(); i++) {
      User organization = orgs.get(i);
      if (organizationsMenu.findItem(organization.id().intValue()) == null) {
        MenuItem organizationMenuItem = organizationsMenu.add(Menu.NONE, organization.id().intValue(), Menu.NONE, organization.name() != null ? organization.name() : organization.login());
        organizationMenuItem.setIcon(R.drawable.ic_github_organization_black_24dp);
        //Because of tinting the real image would became a grey block
        //avatars.bind(organizationMenuItem, organization);
        menuItemOrganizationMap.put(organizationMenuItem, organization);
      }
    }
  } else {
    throw new IllegalStateException("Menu item " + organizationContainer + " should have a submenu");
  }
}

代码示例来源:origin: north2016/T-MVP

@Override
  public boolean onPrepareOptionsMenu(Menu menu) {
    if (collapsedMenu != null && !appBarExpanded)
      collapsedMenu.add("Add").setIcon(R.drawable.ic_menu_send).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    return super.onPrepareOptionsMenu(collapsedMenu);
  }
}

代码示例来源:origin: robolectric/robolectric

@Test
public void getIcon_shouldReturnDrawableFromSetIconDrawable() throws Exception {
 Drawable testDrawable =
   ApplicationProvider.getApplicationContext().getResources().getDrawable(R.drawable.an_image);
 assertThat(testDrawable).isNotNull();
 assertThat(item.getIcon()).isNull();
 item.setIcon(testDrawable);
 assertThat(item.getIcon()).isSameAs(testDrawable);
}

代码示例来源:origin: robolectric/robolectric

@Test
public void setIcon_shouldNullifyOnZero() throws Exception {
 assertThat(item.getIcon()).isNull();
 item.setIcon(R.drawable.an_image);
 assertThat(shadowOf(item.getIcon()).getCreatedFromResId()).isEqualTo(R.drawable.an_image);
 item.setIcon(0);
 assertThat(item.getIcon()).isNull();
}

代码示例来源:origin: TeamNewPipe/NewPipe

private void showServices() {
  serviceArrow.setImageResource(R.drawable.ic_arrow_up_white);
  for(StreamingService s : NewPipe.getServices()) {
    final String title = s.getServiceInfo().getName() +
        (ServiceHelper.isBeta(s) ? " (beta)" : "");
    drawerItems.getMenu()
        .add(R.id.menu_services_group, s.getServiceId(), ORDER, title)
        .setIcon(ServiceHelper.getIcon(s.getServiceId()));
  }
  drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)).setChecked(true);
}

代码示例来源:origin: TeamNewPipe/NewPipe

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  super.onCreateOptionsMenu(menu, inflater);
  final MenuItem restoreItem = menu.add(Menu.NONE, MENU_ITEM_RESTORE_ID, Menu.NONE, R.string.restore_defaults);
  restoreItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
  final int restoreIcon = ThemeHelper.resolveResourceIdFromAttr(requireContext(), R.attr.ic_restore_defaults);
  restoreItem.setIcon(AppCompatResources.getDrawable(requireContext(), restoreIcon));
}

代码示例来源:origin: ZieIony/Carbon

public static Menu getMenu(Context context, android.view.Menu baseMenu) {
  Context contextWrapper = CarbonContextWrapper.wrap(context);
  Menu menu = new Menu(contextWrapper);
  for (int i = 0; i < baseMenu.size(); i++) {
    android.view.MenuItem menuItem = baseMenu.getItem(i);
    menu.add(menuItem.getGroupId(), menuItem.getItemId(), menuItem.getOrder(), menuItem.getTitle()).setIcon(menuItem.getIcon()).setVisible(menuItem.isVisible()).setEnabled(menuItem.isEnabled());
  }
  return menu;
}

代码示例来源:origin: robolectric/robolectric

@Test
public void getIcon_shouldReturnDrawableFromSetIconResourceId() throws Exception {
 assertThat(item.getIcon()).isNull();
 item.setIcon(R.drawable.an_other_image);
 assertThat(shadowOf(item.getIcon()).getCreatedFromResId()).isEqualTo(R.drawable.an_other_image);
}

相关文章