如何在锚点视图的底部始终显示弹出菜单。这是我用来显示弹出菜单的代码。
PopupMenu popup = new PopupMenu(activityReference, view, Gravity.NO_GRAVITY);
popup.getMenuInflater()
.inflate(R.menu.popup_menu_event_edit, popup.getMenu());
popup.show();
我尝试将Gravity.NO_GRAVITY更改为Gravity.BOTTOM。但它不起作用。
答案 0 :(得分:0)
此处button1是锚视图,表示您想要显示菜单的参考
PopupMenu popupMenu = new PopupMenu(context, button1, Gravity.TOP);
popupMenu.getMenuInflater().inflate(R.menu.home_drawer_bottom_nav_menu, popupMenu.getMenu());
popupMenu.show();
答案 1 :(得分:-1)
使用它对我有用。
popupMenu = new PopupMenu(MainActivity.this, anchorView);
popupMenu.inflate(R.menu.popup_menu);
popupMenu.show();