本文整理了Java中java.awt.Menu.getItem()
方法的一些代码示例,展示了Menu.getItem()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Menu.getItem()
方法的具体详情如下:
包路径:java.awt.Menu
类名称:Menu
方法名:getItem
暂无
代码示例来源:origin: stackoverflow.com
@Override
public boolean onPrepareOptionsMenu (Menu menu) {
if (isFinalized) {
menu.getItem(1).setEnabled(false);
// You can also use something like:
// menu.findItem(R.id.example_foobar).setEnabled(false);
}
return true;
}
代码示例来源:origin: net.imagej/ij
/** Inserts 'item' into 'menu' in alphanumeric order. */
static void addOrdered(Menu menu, MenuItem item) {
String label = item.getLabel();
int start = addPluginSeparatorIfNeeded(menu);
for (int i=start; i<menu.getItemCount(); i++) {
if (label.compareTo(menu.getItem(i).getLabel())<0) {
menu.insert(item, i);
return;
}
}
menu.add(item);
}
代码示例来源:origin: stackoverflow.com
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
menu.getItem(0).setEnabled(false); // here pass the index of save menu item
return super.onPrepareOptionsMenu(menu);
}
代码示例来源:origin: stackoverflow.com
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.addprojectmenu, menu);
menu.getItem(0).setEnabled(false); // here pass the index of save menu item
return super.onPrepareOptionsMenu(menu);
}
代码示例来源:origin: stackoverflow.com
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.mapoptions, menu);
int idx=0;
subm = menu.getItem(MYITEM_INDEX).getSubMenu(); // get my MenuItem with placeholder submenu
subm.clear(); // delete place holder
while(true)
{
anarea = m_areas.GetArea(idx); // get a new area, return null if no more areas
if(anarea == null)
break;
subm.add(0, SUBAREASID+idx, idx, anarea.GetName()); // id is idx+ my constant
++idx;
}
}
代码示例来源:origin: stackoverflow.com
private MenuItem securedConnection;
private MenuItem insecuredConnection;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.connect_menu, menu);
securedConnection = menu.getItem(0);
insecuredConnection = menu.getItem(1);
return true;
}
public void foo(){
securedConnection.setEnabled(true);
}
代码示例来源:origin: stackoverflow.com
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
menu.findItem(R.id.sort_by_name).setChecked(true);
//Also you can do this for sub menu
menu.getItem(firstItemIndex).getSubMenu().getItem(subItemIndex).setChecked(true);
return true;
}
代码示例来源:origin: stackoverflow.com
//anywhere in your code
...
mState = HIDE_MENU; // setting state
invalidateOptionsMenu(); // now onCreateOptionsMenu(...) is called again
...
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// inflate menu from xml
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.settings, menu);
if (mState == HIDE_MENU)
{
for (int i = 0; i < menu.size(); i++)
menu.getItem(i).setVisible(false);
}
}
代码示例来源:origin: stackoverflow.com
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.your_menu, menu);
int positionOfMenuItem = 0; // or whatever...
MenuItem item = menu.getItem(positionOfMenuItem);
SpannableString s = new SpannableString("My red MenuItem");
s.setSpan(new ForegroundColorSpan(Color.RED), 0, s.length(), 0);
item.setTitle(s);
}
代码示例来源:origin: stackoverflow.com
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.map_menu, menu);
for (int i = 0; i < menu.size(); i++) {
MenuItem item = menu.getItem(i);
if (item.getItemId() == R.id.menu_more) {
itemChooser = item.getActionView();
if (itemChooser != null) {
itemChooser.setOnClickListener(this);
}
}
}
return super.onCreateOptionsMenu(menu);
}
代码示例来源:origin: stackoverflow.com
navView = (NavigationView) findViewById(R.id.navView);
Menu m = navView.getMenu();
for (int i=0;i<m.size();i++) {
MenuItem mi = m.getItem(i);
//for aapplying a font to subMenu ...
SubMenu subMenu = mi.getSubMenu();
if (subMenu!=null && subMenu.size() >0 ) {
for (int j=0; j <subMenu.size();j++) {
MenuItem subMenuItem = subMenu.getItem(j);
applyFontToMenuItem(subMenuItem);
}
}
//the method we have create in activity
applyFontToMenuItem(mi);
}
代码示例来源:origin: stackoverflow.com
menu.getItem(i).setVisible(!mDrawerLayout.isDrawerOpen(mLeftDrawerView));
代码示例来源:origin: stackoverflow.com
import android.support.v4.internal.view.SupportMenuItem;
import android.support.v7.internal.view.menu.MenuItemImpl;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import here.is.your.R;
public class EnhancedMenuInflater {
public static void inflate(MenuInflater inflater, Menu menu, boolean forceVisible) {
inflater.inflate(R.menu.menu, menu);
if (!forceVisible) {
return;
}
int size = menu.size();
for (int i = 0; i < size; i++) {
MenuItem item = menu.getItem(i);
// check if app:showAsAction = "ifRoom"
if (((MenuItemImpl) item).requestsActionButton()) {
item.setShowAsAction(SupportMenuItem.SHOW_AS_ACTION_ALWAYS);
}
}
}
}
代码示例来源:origin: stackoverflow.com
public static void tintAllIcons(Menu menu, final int color) {
for (int i = 0; i < menu.size(); ++i) {
final MenuItem item = menu.getItem(i);
tintMenuItemIcon(color, item);
tintShareIconIfPresent(color, item);
代码示例来源:origin: stackoverflow.com
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_navigation_drawer); //Converting drawable into bitmap
Bitmap new_icon = resizeBitmapImageFn(icon, 50); //resizing the bitmap
Drawable d = new BitmapDrawable(getResources(),new_icon); //Converting bitmap into drawable
menu.getItem(0).setIcon(d); //choose the item number you want to set
return true;
}
代码示例来源:origin: stackoverflow.com
...
PopupMenu p = new PopupMenu(this, null);
Menu menu = p.getMenu();
getMenuInflater().inflate(R.menu.some_menu, menu);
//Usage of menu
System.out.println("LOG id: "+ menu.getItem(0).getItemId());
System.out.println("LOG title: "+ menu.getItem(0).getTitle());
System.out.println("LOG icon: "+ menu.getItem(0).getIcon());
...
代码示例来源:origin: stackoverflow.com
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
for(int i = 0; i < menu.size(); i++){
Drawable drawable = menu.getItem(i).getIcon();
if(drawable != null) {
drawable.mutate();
drawable.setColorFilter(getResources().getColor(R.color.textColorPrimary), PorterDuff.Mode.SRC_ATOP);
}
}
return true;
}
代码示例来源:origin: stackoverflow.com
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.changeip_card_menu, menu);
for(int i = 0; i < menu.size(); i++) {
MenuItem item = menu.getItem(i);
SpannableString spanString = new SpannableString(menu.getItem(i).getTitle().toString());
spanString.setSpan(new ForegroundColorSpan(Color.WHITE), 0, spanString.length(), 0); //fix the color to white
item.setTitle(spanString);
}
return true;
}
代码示例来源:origin: stackoverflow.com
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.your_menu, menu);
int positionOfMenuItem = 0; // or whatever...
MenuItem item = menu.getItem(positionOfMenuItem);
SpannableString s = new SpannableString("My red MenuItem");
s.setSpan(new ForegroundColorSpan(Color.RED), 0, s.length(), 0);
item.setTitle(s);
}
代码示例来源:origin: stackoverflow.com
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
Log.d(TAG, "onCreateOptionsMenu()");
inflater.inflate(R.menu.your_menu, menu);
for (int j = 0; j < menu.size(); j++) {
MenuItem item = menu.getItem(j);
Log.d(TAG, "set flag for " + item.getTitle());
item.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS);
}
}
内容来源于网络,如有侵权,请联系作者删除!