zwm1210500550
zwm1210500550
采纳率0%
2016-07-30 02:21 阅读 3.2k

android PopupMenu 不能弹出菜单

我每隔一行写了一个System.out,发现前面的代码都运行了,最后的show()没运行。
下面是代码及logcat内容:
PopupMenu popupMenu = new PopupMenu(getBaseContext(), view, 10);
popupMenu.getMenuInflater().inflate(R.menu.list_of_popup_menu, popupMenu.getMenu());
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.hello:
Toast.makeText(getBaseContext(), "hello", Toast.LENGTH_SHORT).show();
case R.id.world:
Toast.makeText(getBaseContext(), "world", Toast.LENGTH_SHORT).show();
}
return true;
}
});
popupMenu.show();

mypopupmenu W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView

mypopupmenu I/ListPopupWindow: Could not find method setEpicenterBounds(Rect) on PopupWindow. Oh well.

mypopupmenu D/AndroidRuntime: Shutting down VM

mypopupmenu E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.zwm12.mypopupmenu, PID: 2926
java.lang.RuntimeException: Failed to resolve attribute at index 6
at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:603)
at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:6423)
at android.view.ViewGroup$MarginLayoutParams.(ViewGroup.java:6591)
at android.widget.FrameLayout$LayoutParams.(FrameLayout.java:735)
at android.widget.FrameLayout.generateLayoutParams(FrameLayout.java:679)
at android.widget.FrameLayout.generateLayoutParams(FrameLayout.java:62)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.support.v7.view.menu.MenuAdapter.getView(MenuAdapter.java:85)
at android.support.v7.view.menu.MenuPopup.measureIndividualMenuWidth(MenuPopup.java:156)
at android.support.v7.view.menu.StandardMenuPopup.tryShow(StandardMenuPopup.java:153)
at android.support.v7.view.menu.StandardMenuPopup.show(StandardMenuPopup.java:187)
at android.support.v7.view.menu.MenuPopupHelper.showPopup(MenuPopupHelper.java:286)
at android.support.v7.view.menu.MenuPopupHelper.tryShow(MenuPopupHelper.java:171)
at android.support.v7.view.menu.MenuPopupHelper.show(MenuPopupHelper.java:137)
at android.support.v7.widget.PopupMenu.show(PopupMenu.java:233)
at com.example.zwm12.mypopupmenu.MainActivity$1.onClick(MainActivity.java:43)
at android.view.View.performClick(View.java:4756)
at android.view.View$PerformClick.run(View.java:19749)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • CSDNXIAOC Robot-C 2016-07-30 02:32

    弹出菜单就是点击某个组件时弹出的菜单。
    Activity类:......
    答案就在这里:【Android】弹出菜单popupmenu
    ----------------------你好,人类,我是来自CSDN星球的问答机器人小C,以上是依据我对问题的理解给出的答案,如果解决了你的问题,望采纳。

    点赞 评论 复制链接分享
  • devmiao devmiao 2016-07-31 15:26

相关推荐