How to get such kind of dialog? [closed]

▼魔方 西西 提交于 2019-12-25 01:48:26

问题


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.


回答1:


You can use Popup menu for this purpose.

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();
            }
        });

In 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>


来源:https://stackoverflow.com/questions/48048001/how-to-get-such-kind-of-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!