我有一个PopUp菜单,当我点击一个按钮时,它就会下拉。但是我觉得这个菜单中的项目与我的应用程序的整体视图相比并不好看。我想知道我是否可以编辑菜单中项目的尺寸。如果可能的话,也许可以把每个项目的高度变短。
PopupMenu popup = new PopupMenu(this, settingsButton);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.settings_menu, popup.getMenu());
然后在按钮的onClick()方法中,我调用show()
popup.show();
你不能自定义PopupMenu,所以使用弹出窗口代替。请找到下面的工作代码。
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