当我点击按钮时,我的PopUp菜单会下降。但是我觉得这个菜单中的项目在我的应用程序的整体视图方面看起来不太好。我想知道我是否可以编辑菜单中项目的尺寸。如果可能的话,也许缩短每个项目的高度。
PopupMenu popup = new PopupMenu(this, settingsButton);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.settings_menu, popup.getMenu());
然后在按钮的onClick()方法中,我调用show()
popup.show();
答案 0 :(得分:0)
您无法自定义PopupMenu,因此请改用Popup窗口。请找到以下工作代码。
PopupWindow popup;
LayoutInflater mInflater = (LayoutInflater) getApplicationContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = mInflater.inflate(R.layout.popuprow, null); //popup row is item xml
layout.measure(View.MeasureSpec.UNSPECIFIED,
View.MeasureSpec.UNSPECIFIED);
popup = new PopupWindow(layout, FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT,true);
final TextView popupMenuitem = (TextView) layout.findViewById(R.id.popupTitle);
// set click on listner on item where you can close the popup by dismiss()
popup.showAsDropDown(filtericon,5,5); // filtericon is button name , clicking
which popup will launch.
popup.dismiss(); // to close popup call this