代码之家  ›  专栏  ›  技术社区  ›  shaktisinghmoyal

如何获得这样的对话?[已关闭]

  •  0
  • shaktisinghmoyal  · 技术社区  · 7 年前

    this is fab button

    this kind of pop up should appear on clicking fab button

    我想在给定的图片中显示某种流行音乐。应该使用什么?弹出窗口、对话框或警报对话框。我已经尝试了所有这些,但无法匹配确切的UI。

    1 回复  |  直到 7 年前
        1
  •  1
  •   Vidhi Dave    7 年前

    您可以使用 Popup menu 为此目的。

    enter image description here

    在活动中添加此代码。java:

    fab.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PopupMenu popup = new PopupMenu(HomeActivity.this, fab);
                    popup.getMenuInflater().inflate(R.menu.menu_home, popup.getMenu());
                    popup.setGravity(Gravity.END);
    
                    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                        public boolean onMenuItemClick(MenuItem item) {
    
                            switch (item.getItemId()) {
                                case R.id.action_settings:
                                    // your action
                                default:
                                    return true;
                            }
                        }
                    });
    
                    popup.show();
                }
            });
    

    在里面 style.xml

      <style name="MyPopupMenu" parent="@style/Widget.AppCompat.PopupMenu.Overflow">
        <item name="fontPath">Muli_Regular.ttf</item>
        <item name="android:dropDownHorizontalOffset">0dp</item>
        <item name="android:dropDownVerticalOffset">57dp</item>
    </style>
    

    使用此 风格 活动主题为:

    <item name="popupMenuStyle">@style/MyPopupMenu</item>