本文整理汇总了Java中android.view.MenuItem.getSubMenu方法的典型用法代码示例。如果您正苦于以下问题:Java MenuItem.getSubMenu方法的具体用法?Java MenuItem.getSubMenu怎么用?Java MenuItem.getSubMenu使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.MenuItem
的用法示例。
在下文中一共展示了MenuItem.getSubMenu方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onActionItemClicked
import android.view.MenuItem; //导入方法依赖的package包/类
@Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
if (BuildConfig.LOG_DEBUG) LogUtils.d(TAG, actionMode, menuItem);
switch (menuItem.getItemId()) {
case R.id.query_cab_schedule:
displayScheduleTimestampDialog(R.id.query_cab_schedule, mSelection.getIds());
break;
case R.id.query_cab_state:
/* Add all known states to menu. */
SubMenu subMenu = menuItem.getSubMenu();
if (subMenu != null) {
subMenu.clear();
for (String str: new NoteStateSpinner(getActivity(), null).getValues()) {
subMenu.add(STATE_ITEM_GROUP, Menu.NONE, Menu.NONE, str);
}
}
break;
default:
/* Click on one of the state keywords. */
if (menuItem.getGroupId() == STATE_ITEM_GROUP) {
if (mListener != null) {
mListener.onStateChangeRequest(mSelection.getIds(), menuItem.getTitle().toString());
}
return true;
}
return false; // Not handled.
}
return true; // Handled.
}
示例2: onActionItemClicked
import android.view.MenuItem; //导入方法依赖的package包/类
@Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
if (BuildConfig.LOG_DEBUG) LogUtils.d(TAG, actionMode, menuItem);
TreeSet<Long> selectionIds;
switch (menuItem.getItemId()) {
case R.id.query_cab_schedule:
selectionIds = originalSelectedIds();
if (!selectionIds.isEmpty()) {
displayScheduleTimestampDialog(R.id.query_cab_schedule, selectionIds);
}
break;
case R.id.query_cab_state:
/* Add all known states to menu. */
SubMenu subMenu = menuItem.getSubMenu();
if (subMenu != null) {
subMenu.clear();
for (String str: new NoteStateSpinner(getActivity(), null).getValues()) {
subMenu.add(STATE_ITEM_GROUP, Menu.NONE, Menu.NONE, str);
}
}
break;
default:
/* Click on one of the state keywords. */
if (menuItem.getGroupId() == STATE_ITEM_GROUP) {
if (mListener != null) {
selectionIds = originalSelectedIds();
if (!selectionIds.isEmpty()) {
mListener.onStateChangeRequest(selectionIds, menuItem.getTitle().toString());
}
}
return true;
}
return false; // Not handled.
}
return true; // Handled.
}
示例3: getSelectedMenu
import android.view.MenuItem; //导入方法依赖的package包/类
public static MenuItem getSelectedMenu(@NonNull MenuItem menuItem) {
if (menuItem.getSubMenu() == null || menuItem.getSubMenu().size() == 0) {
return null;
}
MenuItem selected = null;
for (int i = 0; i < menuItem.getSubMenu().size(); i++) {
MenuItem item = menuItem.getSubMenu().getItem(i);
if (item.isChecked()) {
selected = item;
break;
}
}
return selected;
}
示例4: onCreate
import android.view.MenuItem; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupToolbar(R.id.toolbar, "COOK IT", R.color.colorPink, R.color.colorWhiteTrans, R.drawable.ic_burger);
FragmentTransaction ft;
FragmentHome fragmentHome = new FragmentHome();
ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.frameLayout, fragmentHome).commit();
drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
Menu m = navigationView.getMenu();
for (int i=0;i<m.size();i++) {
MenuItem mi = m.getItem(i);
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);
}
}
applyFontToMenuItem(mi);
}
View header = navigationView.getHeaderView(0);
ImageView imageView = (ImageView) header.findViewById(R.id.imageView);
Glide.with(this)
.load(Uri.parse("https://s3.amazonaws.com/uifaces/faces/twitter/jsa/128.jpg"))
.transform(new CircleGlide(this))
.into(imageView);
}
示例5: createAdapterItems
import android.view.MenuItem; //导入方法依赖的package包/类
private List<BottomSheetItem> createAdapterItems(int dividerBackground, int titleTextColor,
int itemTextColor, int itemBackground,
int tintColor) {
List<BottomSheetItem> items = new ArrayList<>();
mTitles = 0;
boolean addedSubMenu = false;
for (int i = 0; i < mMenu.size(); i++) {
MenuItem item = mMenu.getItem(i);
if (item.isVisible()) {
if (item.hasSubMenu()) {
SubMenu subMenu = item.getSubMenu();
if (i != 0 && addedSubMenu) {
if (mMode == BottomSheetBuilder.MODE_GRID) {
throw new IllegalArgumentException("MODE_GRID can't have submenus." +
" Use MODE_LIST instead");
}
items.add(new BottomSheetDivider(dividerBackground));
}
CharSequence title = item.getTitle();
if (title != null && !title.equals("")) {
items.add(new BottomSheetHeader(title.toString(), titleTextColor));
mTitles++;
}
for (int j = 0; j < subMenu.size(); j++) {
MenuItem subItem = subMenu.getItem(j);
if (subItem.isVisible()) {
items.add(new BottomSheetMenuItem(subItem,itemTextColor, itemBackground, tintColor));
addedSubMenu = true;
}
}
} else {
items.add(new BottomSheetMenuItem(item, itemTextColor, itemBackground, tintColor));
}
}
}
return items;
}