如何获得这种对话? [英] How to get such kind of dialog?

查看:94
本文介绍了如何获得这种对话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to have kind of pop shown in the given images. What should use ? Pop window, dialog or alert dialog. i have tried all of these, but not able to match the exact UI.

推荐答案

您可以使用

You can use Popup menu for this purpose.

将此代码添加到您的activity.java中:

Add this code in your activity.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>

在活动主题中使用以下样式:

use this style in activity theme as :

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

这篇关于如何获得这种对话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆