本文整理了Java中android.view.Menu.getItem()
方法的一些代码示例,展示了Menu.getItem()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Menu.getItem()
方法的具体详情如下:
包路径:android.view.Menu
类名称:Menu
方法名:getItem
暂无
代码示例来源:origin: aurelhubert/ahbottomnavigation
/**
* Get Menu Item
*
* @param index
* @return
*/
public MenuItem getMenuItem(int index) {
return mMenu.getItem(index);
}
代码示例来源:origin: beworker/pinned-section-listview
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
menu.getItem(0).setChecked(isFastScroll);
menu.getItem(1).setChecked(addPadding);
menu.getItem(2).setChecked(isShadowVisible);
return true;
}
代码示例来源:origin: aurelhubert/ahbottomnavigation
/**
* Get position by menu id
*
* @param menuId
* @return
*/
public Integer getPositionByMenuId(int menuId) {
for (int i = 0; i < mMenu.size(); i++) {
if (mMenu.getItem(i).getItemId() == menuId)
return i;
}
return null;
}
}
代码示例来源:origin: square/assertj-android
public MenuAssert hasItemAt(int index) {
isNotNull();
assertThat(actual.getItem(index)) //
.overridingErrorMessage("Expected menu item at index <%s> but was not found.", index) //
.isNotNull();
return this;
}
代码示例来源:origin: TeamNewPipe/NewPipe
private void changeService(MenuItem item) {
drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)).setChecked(false);
ServiceHelper.setSelectedServiceId(this, item.getItemId());
drawerItems.getMenu().getItem(ServiceHelper.getSelectedServiceId(this)).setChecked(true);
}
代码示例来源:origin: ittianyu/BottomNavigationViewEx
/**
* set the current checked item
*
* @param item start from 0.
*/
public BottomNavigationViewEx setCurrentItem(int index) {
setSelectedItemId(getMenu().getItem(index).getItemId());
return this;
}
代码示例来源:origin: ittianyu/BottomNavigationViewEx
/**
* get menu item position in menu
*
* @param item
* @return position if success, -1 otherwise
*/
public int getMenuItemPosition(MenuItem item) {
// get item id
int itemId = item.getItemId();
// get meunu
Menu menu = getMenu();
int size = menu.size();
for (int i = 0; i < size; i++) {
if (menu.getItem(i).getItemId() == itemId) {
return i;
}
}
return -1;
}
代码示例来源:origin: JZ-Darkal/AndroidHttpCapture
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser) {
// initProxyWebView();
((MainActivity) getActivity()).navigationView.getMenu().getItem(0).setChecked(true);
}
}
代码示例来源:origin: ittianyu/BottomNavigationViewEx
MyOnNavigationItemSelectedListener(ViewPager viewPager, BottomNavigationViewEx bnve, boolean smoothScroll, OnNavigationItemSelectedListener listener) {
this.viewPagerRef = new WeakReference<>(viewPager);
this.listener = listener;
this.smoothScroll = smoothScroll;
// create items
Menu menu = bnve.getMenu();
int size = menu.size();
items = new SparseIntArray(size);
for (int i = 0; i < size; i++) {
int itemId = menu.getItem(i).getItemId();
items.put(itemId, i);
}
}
代码示例来源:origin: rey5137/material
/**
* This function should be called in onPrepareOptionsMenu(Menu) of Activity that use
* Toolbar as ActionBar, or after inflating menu.
*/
public void onPrepareMenu(){
if(mGroupChanged || mMenuDataChanged){
mToolbar.getViewTreeObserver().addOnGlobalLayoutListener(mOnGlobalLayoutListener);
Menu menu = mToolbar.getMenu();
for(int i = 0, count = menu.size(); i < count; i++){
MenuItem item = menu.getItem(i);
item.setVisible(item.getGroupId() == mCurrentGroup || item.getGroupId() == 0);
}
mMenuDataChanged = false;
}
}
代码示例来源:origin: ankidroid/Anki-Android
/** Sets selected navigation drawer item */
protected void selectNavigationItem(int itemId) {
if (mNavigationView == null) {
Timber.e("Could not select item in navigation drawer as NavigationView null");
return;
}
Menu menu = mNavigationView.getMenu();
if (itemId == -1) {
for (int i = 0; i < menu.size(); i++) {
menu.getItem(i).setChecked(false);
}
} else {
MenuItem item = menu.findItem(itemId);
if (item != null) {
item.setChecked(true);
} else {
Timber.e("Could not find item %d", itemId);
}
}
}
代码示例来源:origin: ittianyu/BottomNavigationViewEx
/**
* get the current checked item position
*
* @return index of item, start from 0.
*/
public int getCurrentItem() {
/*
1. get field in this class
private final BottomNavigationMenuView mMenuView;
2. get field in mMenuView
private BottomNavigationItemView[] mButtons;
3. get menu and traverse it to get the checked one
*/
// 2. get mButtons
BottomNavigationItemView[] mButtons = getBottomNavigationItemViews();
// 3. get menu and traverse it to get the checked one
Menu menu = getMenu();
for (int i = 0; i < mButtons.length; i++) {
if (menu.getItem(i).isChecked()) {
return i;
}
}
return 0;
}
代码示例来源: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: hidroh/materialistic
/**
* Callback that should be triggered after menu has been inflated
* @param menu inflated menu
*/
public void onOptionsMenuCreated(Menu menu) {
for (int i = 0; i < menu.size(); i++) {
Drawable drawable = menu.getItem(i).getIcon();
if (drawable == null) {
continue;
}
drawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(drawable, mTextColorPrimary);
}
}
代码示例来源: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: aurelhubert/ahbottomnavigation
/**
* Setup bottom navigation (with colors)
*
* @param ahBottomNavigation AHBottomNavigation: Bottom navigation
* @param colors int[]: Colors of the item
*/
public void setupWithBottomNavigation(AHBottomNavigation ahBottomNavigation, @ColorInt int[] colors) {
if (navigationItems == null) {
navigationItems = new ArrayList<>();
} else {
navigationItems.clear();
}
if (mMenu != null) {
for (int i = 0; i < mMenu.size(); i++) {
MenuItem item = mMenu.getItem(i);
if (colors != null && colors.length >= mMenu.size() && colors[i] != 0) {
AHBottomNavigationItem navigationItem = new AHBottomNavigationItem(String.valueOf(item.getTitle()), item.getIcon(), colors[i]);
navigationItems.add(navigationItem);
} else {
AHBottomNavigationItem navigationItem = new AHBottomNavigationItem(String.valueOf(item.getTitle()), item.getIcon());
navigationItems.add(navigationItem);
}
}
ahBottomNavigation.removeAllItems();
ahBottomNavigation.addItems(navigationItems);
}
}
代码示例来源:origin: JohnPersano/SuperToasts
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
final ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(
this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) {
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
// Stop animating the navigation icon
super.onDrawerSlide(drawerView, 0);
}
};
drawerLayout.addDrawerListener(actionBarDrawerToggle);
actionBarDrawerToggle.syncState();
final NavigationView navigationView = (NavigationView) findViewById(R.id.navigation_view);
navigationView.setNavigationItemSelectedListener(this);
navigationView.setCheckedItem(R.id.navigation_drawer_supertoast);
// setCheckedItem() does not actually call the associated listener
if (savedInstanceState == null) this.onNavigationItemSelected(navigationView.getMenu().getItem(0));
}
代码示例来源:origin: code-mc/material-icon-lib
private void populateIcons(Menu menu, IconData root, int defaultIconColor) {
for(int i = 0; i < menu.size(); i++){
MenuItem m = menu.getItem(i);
IconData d = root.children.get(i);
if(m.hasSubMenu()){
populateIcons(m.getSubMenu(), d, defaultIconColor);
}
if(d.itemIconResId >= 0)
m.setIcon(
MaterialDrawableBuilder.with(mContext)
.setIcon(MaterialDrawableBuilder.IconValue.values()[d.itemIconResId])
.setColor(d.itemColor != -1 ? d.itemColor : defaultIconColor)
.setToActionbarSize()
.build()
);
}
}
代码示例来源: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!");
}
代码示例来源:origin: mikepenz/MaterialDrawer
int groupId = R.id.material_drawer_menu_default_group;
for (int i = 0; i < mMenu.size(); i++) {
MenuItem mMenuItem = mMenu.getItem(i);
IDrawerItem iDrawerItem;
if (!subMenu && mMenuItem.getGroupId() != groupId && mMenuItem.getGroupId() != 0) {
内容来源于网络,如有侵权,请联系作者删除!