本文整理匯總了Java中android.support.v7.view.menu.MenuBuilder類的典型用法代碼示例。如果您正苦於以下問題:Java MenuBuilder類的具體用法?Java MenuBuilder怎麽用?Java MenuBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MenuBuilder類屬於android.support.v7.view.menu包,在下文中一共展示了MenuBuilder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onPrepareOptionsPanel
import android.support.v7.view.menu.MenuBuilder; //導入依賴的package包/類
/**
* 顯示item中的圖片;
*
* @param view
* @param menu
* @return
*/
@Override
protected boolean onPrepareOptionsPanel(View view, Menu menu) {
if (menu != null) {
if (menu.getClass() == MenuBuilder.class) {
try {
Method m = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE);
m.setAccessible(true);
m.invoke(menu, true);
} catch (Exception e) {
e.printStackTrace();
}
}
}
return super.onPrepareOptionsPanel(view, menu);
}
示例2: initLeftMenuPop
import android.support.v7.view.menu.MenuBuilder; //導入依賴的package包/類
private void initLeftMenuPop() {
MenuBuilder menuBuilder = new MenuBuilder(getContext());
menuBuilder.setOptionalIconsVisible(true);
menuBuilder.add(R.string.main_single).setIcon(R.drawable.ic_main_single);
menuBuilder.add(R.string.main_multi).setIcon(R.drawable.ic_main_multi);
menuBuilder.add(R.string.main_sticky).setIcon(R.drawable.ic_main_sticky);
menuBuilder.add(R.string.main_sticky_side).setIcon(R.drawable.ic_main_sticky_side);
leftMenuPop = new ListPopupWindow(getContext());
leftMenuPop.setAdapter(new MenuAdapter(menuBuilder, getLayoutInflater(), true));
leftMenuPop.setWidth(getResources().getDisplayMetrics().widthPixels / 2);
leftMenuPop.setHeight(ListPopupWindow.WRAP_CONTENT);
leftMenuPop.setAnchorView(topToolbar);
leftMenuPop.setDropDownGravity(Gravity.START);
leftMenuPop.setModal(true);//設置是否是模式
leftMenuPop.setOnItemClickListener((parent, view, position, id) -> {
mainViewPager.setCurrentItem(position, false);
leftMenuPop.dismiss();
});
}
示例3: invalidateDarkOrLightMenuItems
import android.support.v7.view.menu.MenuBuilder; //導入依賴的package包/類
@SuppressLint("RestrictedApi")
public void invalidateDarkOrLightMenuItems(Context context, Menu menu) {
if (menu != null && menu instanceof MenuBuilder) {
((MenuBuilder) menu).setOptionalIconsVisible(true);
/*final boolean darkMode = ThemeUtils.isDarkMode(context);
final int textColorPrimary = Utils.resolveColor(context, android.R.attr.textColorPrimary);
mToolbar.post(new Runnable() {
@Override
public void run() {
for (int i = 0; i < menu.size(); i++) {
MenuItemImpl item = (MenuItemImpl) menu.getItem(i);
int color = darkMode || item.isActionButton() ? Color.WHITE : textColorPrimary;
if (item.getIcon() != null) {
item.getIcon().setColorFilter(color, PorterDuff.Mode.SRC_IN);
}
}
}
});*/
}
}
示例4: ensureListMenuPresenter
import android.support.v7.view.menu.MenuBuilder; //導入依賴的package包/類
private void ensureListMenuPresenter(Menu menu) {
if (this.mListMenuPresenter == null && (menu instanceof MenuBuilder)) {
MenuBuilder mb = (MenuBuilder) menu;
Context context = this.mDecorToolbar.getContext();
TypedValue outValue = new TypedValue();
Theme widgetTheme = context.getResources().newTheme();
widgetTheme.setTo(context.getTheme());
widgetTheme.resolveAttribute(R.attr.actionBarPopupTheme, outValue, true);
if (outValue.resourceId != 0) {
widgetTheme.applyStyle(outValue.resourceId, true);
}
widgetTheme.resolveAttribute(R.attr.panelMenuListTheme, outValue, true);
if (outValue.resourceId != 0) {
widgetTheme.applyStyle(outValue.resourceId, true);
} else {
widgetTheme.applyStyle(R.style.Theme_AppCompat_CompactMenu, true);
}
Context context2 = new ContextThemeWrapper(context, 0);
context2.getTheme().setTo(widgetTheme);
this.mListMenuPresenter = new ListMenuPresenter(context2, R.layout.abc_list_menu_item_layout);
this.mListMenuPresenter.setCallback(new PanelMenuPresenterCallback());
mb.addMenuPresenter(this.mListMenuPresenter);
}
}
示例5: onCloseMenu
import android.support.v7.view.menu.MenuBuilder; //導入依賴的package包/類
public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) {
MenuBuilder parentMenu = menu.getRootMenu();
boolean isSubMenu = parentMenu != menu;
AppCompatDelegateImplV7 appCompatDelegateImplV7 = AppCompatDelegateImplV7.this;
if (isSubMenu) {
menu = parentMenu;
}
PanelFeatureState panel = appCompatDelegateImplV7.findMenuPanel(menu);
if (panel == null) {
return;
}
if (isSubMenu) {
AppCompatDelegateImplV7.this.callOnPanelClosed(panel.featureId, panel, parentMenu);
AppCompatDelegateImplV7.this.closePanel(panel, true);
return;
}
AppCompatDelegateImplV7.this.closePanel(panel, allMenusAreClosing);
}
示例6: reopenMenu
import android.support.v7.view.menu.MenuBuilder; //導入依賴的package包/類
private void reopenMenu(MenuBuilder menu, boolean toggleMenuMode) {
if (this.mDecorContentParent == null || !this.mDecorContentParent.canShowOverflowMenu() || (ViewConfigurationCompat.hasPermanentMenuKey(ViewConfiguration.get(this.mContext)) && !this.mDecorContentParent.isOverflowMenuShowPending())) {
PanelFeatureState st = getPanelState(0, true);
st.refreshDecorView = true;
closePanel(st, false);
openPanel(st, null);
return;
}
Window.Callback cb = getWindowCallback();
if (this.mDecorContentParent.isOverflowMenuShowing() && toggleMenuMode) {
this.mDecorContentParent.hideOverflowMenu();
if (!isDestroyed()) {
cb.onPanelClosed(108, getPanelState(0, true).menu);
}
} else if (cb != null && !isDestroyed()) {
if (this.mInvalidatePanelMenuPosted && (this.mInvalidatePanelMenuFeatures & 1) != 0) {
this.mWindow.getDecorView().removeCallbacks(this.mInvalidatePanelMenuRunnable);
this.mInvalidatePanelMenuRunnable.run();
}
st = getPanelState(0, true);
if (st.menu != null && !st.refreshMenuContent && cb.onPreparePanel(0, st.createdPanelView, st.menu)) {
cb.onMenuOpened(108, st.menu);
this.mDecorContentParent.showOverflowMenu();
}
}
}
示例7: initializePanelMenu
import android.support.v7.view.menu.MenuBuilder; //導入依賴的package包/類
private boolean initializePanelMenu(PanelFeatureState st) {
Context context = this.mContext;
if ((st.featureId == 0 || st.featureId == 108) && this.mDecorContentParent != null) {
TypedValue outValue = new TypedValue();
Theme baseTheme = context.getTheme();
baseTheme.resolveAttribute(R.attr.actionBarTheme, outValue, true);
Theme widgetTheme = null;
if (outValue.resourceId != 0) {
widgetTheme = context.getResources().newTheme();
widgetTheme.setTo(baseTheme);
widgetTheme.applyStyle(outValue.resourceId, true);
widgetTheme.resolveAttribute(R.attr.actionBarWidgetTheme, outValue, true);
} else {
baseTheme.resolveAttribute(R.attr.actionBarWidgetTheme, outValue, true);
}
if (outValue.resourceId != 0) {
if (widgetTheme == null) {
widgetTheme = context.getResources().newTheme();
widgetTheme.setTo(baseTheme);
}
widgetTheme.applyStyle(outValue.resourceId, true);
}
if (widgetTheme != null) {
Context context2 = new ContextThemeWrapper(context, 0);
context2.getTheme().setTo(widgetTheme);
context = context2;
}
}
MenuBuilder menu = new MenuBuilder(context);
menu.setCallback(this);
st.setMenu(menu);
return true;
}
示例8: expandItemActionView
import android.support.v7.view.menu.MenuBuilder; //導入依賴的package包/類
public boolean expandItemActionView(MenuBuilder menu, MenuItemImpl item) {
Toolbar.this.ensureCollapseButtonView();
if (Toolbar.this.mCollapseButtonView.getParent() != Toolbar.this) {
Toolbar.this.addView(Toolbar.this.mCollapseButtonView);
}
Toolbar.this.mExpandedActionView = item.getActionView();
this.mCurrentExpandedItem = item;
if (Toolbar.this.mExpandedActionView.getParent() != Toolbar.this) {
LayoutParams lp = Toolbar.this.generateDefaultLayoutParams();
lp.gravity = GravityCompat.START | (Toolbar.this.mButtonGravity & 112);
lp.mViewType = 2;
Toolbar.this.mExpandedActionView.setLayoutParams(lp);
Toolbar.this.addView(Toolbar.this.mExpandedActionView);
}
Toolbar.this.removeChildrenForExpandedActionView();
Toolbar.this.requestLayout();
item.setActionViewExpanded(true);
if (Toolbar.this.mExpandedActionView instanceof CollapsibleActionView) {
((CollapsibleActionView) Toolbar.this.mExpandedActionView).onActionViewExpanded();
}
return true;
}
示例9: initForMode
import android.support.v7.view.menu.MenuBuilder; //導入依賴的package包/類
public void initForMode(final ActionMode mode) {
if (this.mClose == null) {
this.mClose = LayoutInflater.from(getContext()).inflate(this.mCloseItemLayout, this, false);
addView(this.mClose);
} else if (this.mClose.getParent() == null) {
addView(this.mClose);
}
this.mClose.findViewById(R.id.action_mode_close_button).setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mode.finish();
}
});
MenuBuilder menu = (MenuBuilder) mode.getMenu();
if (this.mActionMenuPresenter != null) {
this.mActionMenuPresenter.dismissPopupMenus();
}
this.mActionMenuPresenter = new ActionMenuPresenter(getContext());
this.mActionMenuPresenter.setReserveOverflow(true);
LayoutParams layoutParams = new LayoutParams(-2, -1);
menu.addMenuPresenter(this.mActionMenuPresenter, this.mPopupContext);
this.mMenuView = (ActionMenuView) this.mActionMenuPresenter.getMenuView(this);
this.mMenuView.setBackgroundDrawable(null);
addView(this.mMenuView, layoutParams);
}
示例10: forceMenuIcons
import android.support.v7.view.menu.MenuBuilder; //導入依賴的package包/類
/**
* Uses some clever trickery to make it so that menu items in the popup menu still show their icons. (Very hacky)
* @param menu Menu to force icons for.
* @param classSimpleName Class name, used for potential logging.
*/
public static void forceMenuIcons(Menu menu, String classSimpleName) {
if (menu != null) {
// Make sure all icons are tinted the correct color, including those in the overflow menu.
for (int i = 0; i < menu.size(); i++)
menu.getItem(i).getIcon().setColorFilter(
ContextCompat.getColor(Minerva.get(), R.color.textColorPrimary), PorterDuff.Mode.SRC_IN);
// And use a bit of reflection to ensure we show icons even in the overflow menu.
if (menu.getClass().equals(MenuBuilder.class)) {
try {
Method m = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE);
m.setAccessible(true);
m.invoke(menu, true);
} catch (Exception e) {
Timber.tag(classSimpleName);
Timber.e(e, "onMenuOpened...unable to set icons for overflow menu");
}
}
}
}
示例11: MenuPopupHelper
import android.support.v7.view.menu.MenuBuilder; //導入依賴的package包/類
public MenuPopupHelper(Context context, MenuBuilder menu, View anchorView,
boolean overflowOnly, int popupStyleAttr, int popupStyleRes) {
mContext = context;
mInflater = LayoutInflater.from(context);
mMenu = menu;
mAdapter = new MenuAdapter(mMenu);
mOverflowOnly = overflowOnly;
mPopupStyleAttr = popupStyleAttr;
mPopupStyleRes = popupStyleRes;
final Resources res = context.getResources();
mPopupMaxWidth = Math.max(res.getDisplayMetrics().widthPixels / 2,
res.getDimensionPixelSize(R.dimen.abc_config_prefDialogWidth));
mAnchorView = anchorView;
// Present the menu using our context, not the menu builder's context.
menu.addMenuPresenter(this, context);
}
示例12: reset
import android.support.v7.view.menu.MenuBuilder; //導入依賴的package包/類
/**
* Resets the the view to fit into a new available width.
* <p>
* This clears and then re-inflates the menu items, removes all of its associated action
* views, and re-creates the menu and action items to fit in the new width.
* </p>
*
* @param menuItemsRoom the number of the menu items to show. If
* there is room, menu items that are flagged with
* android:showAsAction="ifRoom" or android:showAsAction="always"
* will show as actions.
*/
public void reset(final int menu, int menuItemsRoom) {
mMenuResId = menu;
//clean view and re-inflate
removeAllViews();
if (mMenuResId == -1) {
return;
}
final MenuBuilder builder = new MenuBuilder(getContext());
getMenuInflater().inflate(mMenuResId, builder);
reset(builder, menuItemsRoom);
}
示例13: initRightMenuPop
import android.support.v7.view.menu.MenuBuilder; //導入依賴的package包/類
private void initRightMenuPop() {
MenuBuilder menuBuilder = new MenuBuilder(getContext());
menuBuilder.setOptionalIconsVisible(true);
menuBuilder.add(R.string.main_asc).setIcon(R.drawable.ic_main_asc);
menuBuilder.add(R.string.main_desc).setIcon(R.drawable.ic_main_desc);
menuBuilder.add(R.string.main_shuffle).setIcon(R.drawable.ic_main_shuffle);
rightMenuPop = new ListPopupWindow(getContext());
rightMenuPop.setAdapter(new MenuAdapter(menuBuilder, getLayoutInflater(), true));
rightMenuPop.setWidth(getResources().getDisplayMetrics().widthPixels / 2);
rightMenuPop.setHeight(ListPopupWindow.WRAP_CONTENT);
rightMenuPop.setAnchorView(topToolbar);
rightMenuPop.setDropDownGravity(Gravity.END);
rightMenuPop.setModal(true);//設置是否是模式
rightMenuPop.setOnItemClickListener((parent, view, position, id) -> {
switch (position) {
case 0:
fragmentAdapter.getItem(mainViewPager.getCurrentItem()).asc();
break;
case 1:
fragmentAdapter.getItem(mainViewPager.getCurrentItem()).desc();
break;
case 2:
fragmentAdapter.getItem(mainViewPager.getCurrentItem()).shuffle();
break;
}
rightMenuPop.dismiss();
});
}
示例14: inflateMenu
import android.support.v7.view.menu.MenuBuilder; //導入依賴的package包/類
void inflateMenu(int menu, OnItemClickListener onItemClickListener) {
MenuInflater menuInflater = new SupportMenuInflater(getContext());
MenuBuilder menuBuilder = new MenuBuilder(getContext());
menuInflater.inflate(menu, menuBuilder);
List<CustomItem> items = new ArrayList<>();
for (int i = 0; i < menuBuilder.size(); i++) {
MenuItem menuItem = menuBuilder.getItem(i);
items.add(new CustomItem(menuItem.getItemId(), menuItem.getTitle().toString(), menuItem.getIcon()));
}
addItems(items, onItemClickListener);
}
示例15: initialize
import android.support.v7.view.menu.MenuBuilder; //導入依賴的package包/類
@Override
public void initialize(MenuBuilder menu) {
mMenu = menu;
if (mMenu == null) return;
if (mMenu.size() > mActiveButton) {
mMenu.getItem(mActiveButton).setChecked(true);
}
}