您无法自定义 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