5

I have a PopUp Menu that drops down when I click a button. However I feel the items in this menu don't look good with respect to the overall view of my App. I was wondering if I could edit the dimensions of the items in the Menu. Maybe make the height of each item shorter, if possible.

PopupMenu popup = new PopupMenu(this, settingsButton);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.settings_menu, popup.getMenu());

Then in the onClick() method of the button I call show()

popup.show();
calm_mind
  • 85
  • 1
  • 5

1 Answers1

0

You cant customize PopupMenu so use Popup window instead. PLease find the below working code.

   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
Akash kumar
  • 981
  • 3
  • 14
  • 27