【问题标题】:How can I edit the dimensions of a PopUp Menu Item in Android?如何在 Android 中编辑弹出菜单项的尺寸?
【发布时间】:2012-08-28 18:37:10
【问题描述】:

我有一个弹出菜单,当我单击按钮时会下拉。但是我觉得这个菜单中的项目相对于我的应用程序的整体视图看起来不太好。我想知道是否可以编辑菜单中项目的尺寸。如果可能的话,也许让每个项目的高度更短。

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

然后在按钮的onClick()方法中我调用show()

popup.show();

【问题讨论】:

  • 查看弹出菜单的代码是什么?发布那个

标签: android xml menu popupmenu


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-28
    • 2018-06-30
    • 2015-06-11
    • 2021-07-29
    • 2016-04-15
    相关资源
    最近更新 更多