本文整理匯總了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;
}