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

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

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

暂无

代码示例

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

MenuItem mi = m.getItem(m.size()-1);
 mi.setTitle(mi.getTitle());

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

private void applyFontToMenuItem(MenuItem mi) {
    Typeface font = Typeface.createFromAsset(getAssets(), "ds_digi_b.TTF");
    SpannableString mNewTitle = new SpannableString(mi.getTitle());
    mNewTitle.setSpan(new CustomTypefaceSpan("" , font), 0 , mNewTitle.length(),  Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    mi.setTitle(mNewTitle);
}

代码示例来源:origin: mxn21/FlowingDrawer

@Override
  public boolean onNavigationItemSelected(MenuItem menuItem) {
    Toast.makeText(getActivity(),menuItem.getTitle(),Toast.LENGTH_SHORT).show();
    return false;
  }
}) ;

代码示例来源:origin: mmin18/RealtimeBlurView

@Override
public boolean onOptionsItemSelected(MenuItem item) {
  if ("Popup".equals(item.getTitle())) {
    showPopup();
  } else if ("List".equals(item.getTitle())) {
    startActivity(new Intent(this, ListActivity.class));
  }
  return true;
}

代码示例来源:origin: Flipboard/bottomsheet

@Override
  public boolean onMenuItemClick(MenuItem item) {
    Toast.makeText(MenuActivity.this, item.getTitle(), Toast.LENGTH_SHORT).show();
    if (bottomSheetLayout.isSheetShowing()) {
      bottomSheetLayout.dismissSheet();
    }
    if (item.getItemId() == R.id.reopen) {
      showMenuSheet(menuType == MenuSheetView.MenuType.LIST ? MenuSheetView.MenuType.GRID : MenuSheetView.MenuType.LIST);
    }
    return true;
  }
});

代码示例来源:origin: square/assertj-android

public MenuItemAssert hasTitle(CharSequence title) {
 isNotNull();
 CharSequence actualTitle = actual.getTitle();
 assertThat(actualTitle) //
   .overridingErrorMessage("Expected title <%s> but was <%s>.", title, actualTitle) //
   .isEqualTo(title);
 return this;
}

代码示例来源:origin: Flipboard/bottomsheet

public void bindView(SheetMenuItem item) {
    icon.setImageDrawable(item.getMenuItem().getIcon());
    label.setText(item.getMenuItem().getTitle());
  }
}

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

private MenuItem getMockMenuItem(int id, String title) {
  MenuItem mockedMenuItem = mock(MenuItem.class);
  when(mockedMenuItem.getItemId()).thenReturn(id);
  when(mockedMenuItem.getTitle()).thenReturn(title);
  return mockedMenuItem;
}

代码示例来源:origin: nekocode/CameraFilter

@Override
public boolean onOptionsItemSelected(MenuItem item) {
  filterId = item.getItemId();
  // TODO: need tidy up
  if (filterId == R.id.capture) {
    Toast.makeText(this,
        capture() ? "The capture has been saved to your sdcard root path." :
            "Save failed!",
        Toast.LENGTH_SHORT).show();
    return true;
  }
  setTitle(item.getTitle());
  if (renderer != null)
    renderer.setSelectedFilter(filterId);
  return true;
}

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

Toast.makeText(
  MainActivity.this,
  "You Clicked : " + item.getTitle(),
  Toast.LENGTH_SHORT
).show();

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

/**
 * Called when an item of the quality selector or the playback speed selector is selected
 */
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
  if (DEBUG)
    Log.d(TAG, "onMenuItemClick() called with: menuItem = [" + menuItem + "], menuItem.getItemId = [" + menuItem.getItemId() + "]");
  if (qualityPopupMenuGroupId == menuItem.getGroupId()) {
    final int menuItemIndex = menuItem.getItemId();
    if (selectedStreamIndex == menuItemIndex ||
        availableStreams == null || availableStreams.size() <= menuItemIndex) return true;
    final String newResolution = availableStreams.get(menuItemIndex).resolution;
    setRecovery();
    setPlaybackQuality(newResolution);
    reload();
    qualityTextView.setText(menuItem.getTitle());
    return true;
  } else if (playbackSpeedPopupMenuGroupId == menuItem.getGroupId()) {
    int speedIndex = menuItem.getItemId();
    float speed = PLAYBACK_SPEEDS[speedIndex];
    setPlaybackSpeed(speed);
    playbackSpeedTextView.setText(formatSpeed(speed));
  }
  return false;
}

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

public void onPopupButtonClick(View button) {
  PopupMenu popup = new PopupMenu(this, button);
  popup.getMenuInflater().inflate(R.menu.popup, popup.getMenu());

  popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
    public boolean onMenuItemClick(MenuItem item) {
      Toast.makeText(PopupMenu1.this, "Clicked popup menu item " + item.getTitle(),
        Toast.LENGTH_SHORT).show();
      return true;
    }
  });

  popup.show();
}

代码示例来源:origin: arimorty/floatingsearchview

@Override
  public void onActionMenuItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.action_change_colors) {
      mIsDarkSearchTheme = true;
      //demonstrate setting colors for items
      mSearchView.setBackgroundColor(Color.parseColor("#787878"));
      mSearchView.setViewTextColor(Color.parseColor("#e9e9e9"));
      mSearchView.setHintTextColor(Color.parseColor("#e9e9e9"));
      mSearchView.setActionMenuOverflowColor(Color.parseColor("#e9e9e9"));
      mSearchView.setMenuItemIconColor(Color.parseColor("#e9e9e9"));
      mSearchView.setLeftActionIconColor(Color.parseColor("#e9e9e9"));
      mSearchView.setClearBtnColor(Color.parseColor("#e9e9e9"));
      mSearchView.setDividerColor(Color.parseColor("#BEBEBE"));
      mSearchView.setLeftActionIconColor(Color.parseColor("#e9e9e9"));
    } else {
      //just print action
      Toast.makeText(getActivity().getApplicationContext(), item.getTitle(),
          Toast.LENGTH_SHORT).show();
    }
  }
});

代码示例来源:origin: arimorty/floatingsearchview

@Override
  public void onActionMenuItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.action_change_colors) {
      mIsDarkSearchTheme = true;
      //demonstrate setting colors for items
      mSearchView.setBackgroundColor(Color.parseColor("#787878"));
      mSearchView.setViewTextColor(Color.parseColor("#e9e9e9"));
      mSearchView.setHintTextColor(Color.parseColor("#e9e9e9"));
      mSearchView.setActionMenuOverflowColor(Color.parseColor("#e9e9e9"));
      mSearchView.setMenuItemIconColor(Color.parseColor("#e9e9e9"));
      mSearchView.setLeftActionIconColor(Color.parseColor("#e9e9e9"));
      mSearchView.setClearBtnColor(Color.parseColor("#e9e9e9"));
      mSearchView.setDividerColor(Color.parseColor("#BEBEBE"));
      mSearchView.setLeftActionIconColor(Color.parseColor("#e9e9e9"));
    } else {
      //just print action
      Toast.makeText(getActivity().getApplicationContext(), item.getTitle(),
          Toast.LENGTH_SHORT).show();
    }
  }
});

代码示例来源:origin: arimorty/floatingsearchview

@Override
  public void onActionMenuItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.action_change_colors) {
      mIsDarkSearchTheme = true;
      //demonstrate setting colors for items
      mSearchView.setBackgroundColor(Color.parseColor("#787878"));
      mSearchView.setViewTextColor(Color.parseColor("#e9e9e9"));
      mSearchView.setHintTextColor(Color.parseColor("#e9e9e9"));
      mSearchView.setActionMenuOverflowColor(Color.parseColor("#e9e9e9"));
      mSearchView.setMenuItemIconColor(Color.parseColor("#e9e9e9"));
      mSearchView.setLeftActionIconColor(Color.parseColor("#e9e9e9"));
      mSearchView.setClearBtnColor(Color.parseColor("#e9e9e9"));
      mSearchView.setDividerColor(Color.parseColor("#BEBEBE"));
      mSearchView.setLeftActionIconColor(Color.parseColor("#e9e9e9"));
    } else {
      //just print action
      Toast.makeText(getActivity().getApplicationContext(), item.getTitle(),
          Toast.LENGTH_SHORT).show();
    }
  }
});

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

@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
  int itemId = menuItem.getItemId();
  if (itemId == R.id.navigation_home) {
    switchFragment(new HomePagerFragment(), org);
    getSupportActionBar().setTitle(getString(R.string.app_name));
    return true;
  } else if (itemId == R.id.navigation_gists) {
    switchFragment(new GistsPagerFragment(), null);
    getSupportActionBar().setTitle(menuItem.getTitle());
    return true;
  } else if (itemId == R.id.navigation_issue_dashboard) {
    switchFragment(new IssueDashboardPagerFragment(), null);
    getSupportActionBar().setTitle(menuItem.getTitle());
    return true;
  } else if (itemId == R.id.navigation_bookmarks) {
    switchFragment(new FilterListFragment(), null);
    getSupportActionBar().setTitle(menuItem.getTitle());
    return true;
  } else if (itemId == R.id.navigation_log_out) {
    logout();
    return false;
  } else if (menuItemOrganizationMap.containsKey(menuItem)) {
    switchFragment(new HomePagerFragment(), menuItemOrganizationMap.get(menuItem));
    navigationView.getMenu().findItem(R.id.navigation_home).setChecked(true);
    return false;
  } else {
    throw new IllegalStateException("MenuItem " + menuItem + " not known");
  }
}

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

private void initMenuItem(final MenuItem item, Button button) {
  if (item != null) {
    button.setText(item.getTitle());
    button.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
        editText.onTextContextMenuItem(item.getItemId());
        dismiss();
      }
    });
    button.setVisibility(View.VISIBLE);
  } else {
    button.setVisibility(View.GONE);
  }
}

代码示例来源: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 add_AddsItemsInOrder() {
  RoboMenu menu = new RoboMenu(ApplicationProvider.getApplicationContext());
  menu.add(0, 0, 1, "greeting");
  menu.add(0, 0, 0, "hell0");
  menu.add(0, 0, 0, "hello");

  MenuItem item = menu.getItem(0);
  assertEquals("hell0", item.getTitle());
  item = menu.getItem(1);
  assertEquals("hello", item.getTitle());
  item = menu.getItem(2);
  assertEquals("greeting", item.getTitle());
 }
}

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

@Test
public void canGetOptionsMenu() throws Exception {
 Activity activity = buildActivity(OptionsMenuActivity.class).create().visible().get();
 Menu optionsMenu = shadowOf(activity).getOptionsMenu();
 assertThat(optionsMenu).isNotNull();
 assertThat(optionsMenu.getItem(0).getTitle()).isEqualTo("Algebraic!");
}

相关文章