本文整理汇总了Java中android.support.v7.view.menu.MenuPopupHelper类的典型用法代码示例。如果您正苦于以下问题:Java MenuPopupHelper类的具体用法?Java MenuPopupHelper怎么用?Java MenuPopupHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MenuPopupHelper类属于android.support.v7.view.menu包,在下文中一共展示了MenuPopupHelper类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: showPopupMenu
import android.support.v7.view.menu.MenuPopupHelper; //导入依赖的package包/类
public void showPopupMenu(View view) throws NoSuchFieldException, IllegalAccessException {
PopupMenu popupMenu = new PopupMenu(this, view);
//设置 PopupMenu 的显示菜单项
popupMenu.inflate(R.menu.main);
// popupMenu.getMenuInflater().inflate(R.menu.main, popupMenu.getMenu());//与一行没什么区别
//默认 PopupMenu 不显示条目icon,可以通过反射来强制使其显示icon
Field field = popupMenu.getClass().getDeclaredField("mPopup");
field.setAccessible(true);
MenuPopupHelper mHelper = (MenuPopupHelper) field.get(popupMenu);
mHelper.setForceShowIcon(true);
//设置 PopupMenu 的条目点击事件(点击后会自动dismiss)
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Toast.makeText(getApplicationContext(), item.getTitle(), Toast.LENGTH_SHORT).show();
return false;
}
});
//显示 PopupMenu
popupMenu.show();
}
开发者ID:GitLqr,项目名称:MaterialDesignDemo,代码行数:22,代码来源:PopupMenuActivity.java
示例2: onClick
import android.support.v7.view.menu.MenuPopupHelper; //导入依赖的package包/类
@Override
public void onClick(View v) {
MenuPopupHelper menuHelper = new MenuPopupHelper(this,
(MenuBuilder) mLayerTypePopup.getMenu(),
mBinding.addLayerBtn);
menuHelper.setForceShowIcon(true);
menuHelper.show();
}
开发者ID:google,项目名称:spline,代码行数:9,代码来源:EditorActivity.java
示例3: onSubMenuSelected
import android.support.v7.view.menu.MenuPopupHelper; //导入依赖的package包/类
public boolean onSubMenuSelected(SubMenuBuilder subMenu) {
if (this.mCallback == null) {
return false;
}
if (!subMenu.hasVisibleItems()) {
return true;
}
new MenuPopupHelper(WindowDecorActionBar.this.getThemedContext(), subMenu).show();
return true;
}
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:11,代码来源:WindowDecorActionBar.java
示例4: PopupMenu
import android.support.v7.view.menu.MenuPopupHelper; //导入依赖的package包/类
public PopupMenu(Context context, View anchor, int gravity, int popupStyleAttr, int popupStyleRes) {
this.mContext = context;
this.mMenu = new MenuBuilder(context);
this.mMenu.setCallback(this);
this.mAnchor = anchor;
this.mPopup = new MenuPopupHelper(context, this.mMenu, anchor, false, popupStyleAttr, popupStyleRes);
this.mPopup.setGravity(gravity);
this.mPopup.setCallback(this);
}
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:10,代码来源:PopupMenu.java
示例5: onOpenSubMenu
import android.support.v7.view.menu.MenuPopupHelper; //导入依赖的package包/类
public boolean onOpenSubMenu(MenuBuilder subMenu) {
if (subMenu == null) {
return false;
}
if (!subMenu.hasVisibleItems()) {
return true;
}
new MenuPopupHelper(this.mContext, subMenu, this.mAnchor).show();
return true;
}
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:11,代码来源:PopupMenu.java
示例6: hideOverflowMenu
import android.support.v7.view.menu.MenuPopupHelper; //导入依赖的package包/类
public boolean hideOverflowMenu() {
if (this.mPostedOpenRunnable == null || this.mMenuView == null) {
MenuPopupHelper popup = this.mOverflowPopup;
if (popup == null) {
return false;
}
popup.dismiss();
return true;
}
((View) this.mMenuView).removeCallbacks(this.mPostedOpenRunnable);
this.mPostedOpenRunnable = null;
return true;
}
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:14,代码来源:ActionMenuPresenter.java
示例7: showVisibilityMenu
import android.support.v7.view.menu.MenuPopupHelper; //导入依赖的package包/类
public void showVisibilityMenu(View v) {
final ImageButton rV = (ImageButton) v;
PopupMenu popup = new PopupMenu(SendToot.this, v);
popup.getMenuInflater().inflate(R.menu.set_visibility_menu, popup.getMenu());
popup.setOnMenuItemClickListener((MenuItem item) -> {
Log.d(TAG, String.valueOf(item.getItemId()));
rV.setImageDrawable(item.getIcon());
switch(item.getItemId()) {
case R.id.visibility_public:
ToastMaker.buildToasty(this, "Your post will appear in public timelines").show();
break;
case R.id.visibility_unlisted:
ToastMaker.buildToasty(this, "Your post will not appear public timelines").show();
break;
case R.id.visibility_private:
ToastMaker.buildToasty(this, "Your post will appear to followers only").show();
break;
case R.id.visibility_direct:
ToastMaker.buildToasty(this, "Your post will appear to mentioned user only").show();
break;
default:
Log.d(TAG, "memes");
}
return true;
});
MenuPopupHelper menuHelper = new MenuPopupHelper(SendToot.this, (MenuBuilder) popup.getMenu(), v);
menuHelper.setForceShowIcon(true);
menuHelper.show();
}
开发者ID:gsora,项目名称:TootApp,代码行数:33,代码来源:SendToot.java
示例8: applyOverflow
import android.support.v7.view.menu.MenuPopupHelper; //导入依赖的package包/类
public static void applyOverflow(final @NonNull Activity activity, final @Nullable String key, final @Nullable Toolbar toolbar) {
if (toolbar == null) return;
toolbar.post(new Runnable() {
@Override
public void run() {
try {
Field f1 = Toolbar.class.getDeclaredField("mMenuView");
f1.setAccessible(true);
ActionMenuView actionMenuView = (ActionMenuView) f1.get(toolbar);
Field f2 = ActionMenuView.class.getDeclaredField("mPresenter");
f2.setAccessible(true);
// Actually ActionMenuPresenter
BaseMenuPresenter presenter = (BaseMenuPresenter) f2.get(actionMenuView);
Field f3 = presenter.getClass().getDeclaredField("mOverflowPopup");
f3.setAccessible(true);
MenuPopupHelper overflowMenuPopupHelper = (MenuPopupHelper) f3.get(presenter);
setTintForMenuPopupHelper(activity, overflowMenuPopupHelper, key);
Field f4 = presenter.getClass().getDeclaredField("mActionButtonPopup");
f4.setAccessible(true);
MenuPopupHelper subMenuPopupHelper = (MenuPopupHelper) f4.get(presenter);
setTintForMenuPopupHelper(activity, subMenuPopupHelper, key);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
开发者ID:cseshaiban,项目名称:app-theme-engine-master,代码行数:30,代码来源:ATE.java
示例9: IconizedPopup
import android.support.v7.view.menu.MenuPopupHelper; //导入依赖的package包/类
/**
* Construct a new PopupMenu.
*
* @param context Context for the PopupMenu.
* @param anchor Anchor view for this popup. The popup will appear below the anchor if there
* is room, or above it if there is not.
*/
public IconizedPopup (Context context, View anchor) {
mContext = context;
mMenu = new MenuBuilder(context);
mMenu.setCallback(this);
mAnchor = anchor;
mPopup = new MenuPopupHelper(context, mMenu, anchor);
mPopup.setCallback(this);
mPopup.setForceShowIcon(true);
}
开发者ID:AvijitGhosh82,项目名称:Madad_SOS,代码行数:17,代码来源:IconizedPopup.java
示例10: onOpenSubMenu
import android.support.v7.view.menu.MenuPopupHelper; //导入依赖的package包/类
/**
* @hide
*/
public boolean onOpenSubMenu(MenuBuilder subMenu) {
if (subMenu == null) return false;
if (!subMenu.hasVisibleItems()) {
return true;
}
// Current menu will be dismissed by the normal helper, submenu will be shown in its place.
new MenuPopupHelper(mContext, subMenu, mAnchor).show();
return true;
}
开发者ID:AvijitGhosh82,项目名称:Madad_SOS,代码行数:15,代码来源:IconizedPopup.java
示例11: applyOverflowMenuTint
import android.support.v7.view.menu.MenuPopupHelper; //导入依赖的package包/类
public static void applyOverflowMenuTint(final @NonNull Context context, final Toolbar toolbar, final @ColorInt int color) {
if (toolbar == null) return;
toolbar.post(new Runnable() {
@Override
public void run() {
try {
Field f1 = Toolbar.class.getDeclaredField("mMenuView");
f1.setAccessible(true);
ActionMenuView actionMenuView = (ActionMenuView) f1.get(toolbar);
Field f2 = ActionMenuView.class.getDeclaredField("mPresenter");
f2.setAccessible(true);
// Actually ActionMenuPresenter
BaseMenuPresenter presenter = (BaseMenuPresenter) f2.get(actionMenuView);
Field f3 = presenter.getClass().getDeclaredField("mOverflowPopup");
f3.setAccessible(true);
MenuPopupHelper overflowMenuPopupHelper = (MenuPopupHelper) f3.get(presenter);
setTintForMenuPopupHelper(context, overflowMenuPopupHelper, color);
Field f4 = presenter.getClass().getDeclaredField("mActionButtonPopup");
f4.setAccessible(true);
MenuPopupHelper subMenuPopupHelper = (MenuPopupHelper) f4.get(presenter);
setTintForMenuPopupHelper(context, subMenuPopupHelper, color);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
开发者ID:punchup,项目名称:Superuser-UI,代码行数:30,代码来源:ToolbarContentTintHelper.java
示例12: makePopForceShowIcon
import android.support.v7.view.menu.MenuPopupHelper; //导入依赖的package包/类
private void makePopForceShowIcon(PopupMenu popupMenu) {
try {
Field mFieldPopup=popupMenu.getClass().getDeclaredField("mPopup");
mFieldPopup.setAccessible(true);
MenuPopupHelper mPopup = (MenuPopupHelper) mFieldPopup.get(popupMenu);
mPopup.setForceShowIcon(true);
} catch (Exception e) {
}
}
开发者ID:maoruibin,项目名称:AppPlus,代码行数:11,代码来源:AppInfoListAdapter.java
示例13: onSubMenuSelected
import android.support.v7.view.menu.MenuPopupHelper; //导入依赖的package包/类
public boolean onSubMenuSelected(SubMenuBuilder subMenu) {
if (subMenu.hasVisibleItems()) {
new MenuPopupHelper(this.mContextView.getContext(), subMenu).show();
}
return true;
}
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:7,代码来源:StandaloneActionMode.java
示例14: setTintForMenuPopupHelper
import android.support.v7.view.menu.MenuPopupHelper; //导入依赖的package包/类
private static void setTintForMenuPopupHelper(final @NonNull Activity context, @Nullable MenuPopupHelper menuPopupHelper, final @Nullable String key) {
if (menuPopupHelper != null) {
final ListView listView = menuPopupHelper.getPopup().getListView();
listView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
try {
Field checkboxField = ListMenuItemView.class.getDeclaredField("mCheckBox");
checkboxField.setAccessible(true);
Field radioButtonField = ListMenuItemView.class.getDeclaredField("mRadioButton");
radioButtonField.setAccessible(true);
final boolean isDark = !Util.isColorLight(Util.resolveColor(context, android.R.attr.windowBackground));
for (int i = 0; i < listView.getChildCount(); i++) {
View v = listView.getChildAt(i);
if (!(v instanceof ListMenuItemView)) continue;
ListMenuItemView iv = (ListMenuItemView) v;
CheckBox check = (CheckBox) checkboxField.get(iv);
if (check != null) {
TintHelper.setTint(check, Config.accentColor(context, key), isDark);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
check.setBackground(null);
}
RadioButton radioButton = (RadioButton) radioButtonField.get(iv);
if (radioButton != null) {
TintHelper.setTint(radioButton, Config.accentColor(context, key), isDark);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
radioButton.setBackground(null);
}
}
} catch (Throwable e) {
e.printStackTrace();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
listView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
} else {
//noinspection deprecation
listView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
}
});
}
}
开发者ID:cseshaiban,项目名称:app-theme-engine-master,代码行数:47,代码来源:ATE.java
注:本文中的android.support.v7.view.menu.MenuPopupHelper类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论