Nick Mowen
Nick Mowen

Reputation: 2622

How to create the mini dialogs (with pictures)

I've seen these dialogs around certain apps but I haven't been able to figure out how to show / create them. Am I missing something obvious? Thanks for your help!

enter image description here

Upvotes: 2

Views: 63

Answers (1)

dzikovskyy
dzikovskyy

Reputation: 5087

You can create PopupMenu.

First create popup_menu.xml file in res/menu folder:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
      tools:context=".MainActivity">

    <item
        android:id="@+id/action_copy"
        android:orderInCategory="100"
        android:title="@string/action_copy"/>

    <item
        android:id="@+id/action_forvard"
        android:orderInCategory="110"
        android:title="@string/action_forvard"/>

</menu>

Then implement PopupMenu inside onClick() method of onClickListener of your view:

@Override
public void onClick(View view) {
    PopupMenu popup = new PopupMenu(MainActivity.this, view);
    popup.getMenuInflater().inflate(R.menu.popup_menu, popup.getMenu());
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
                case R.id.action_copy:
                    //your code here
                    break;
                case R.id.action_forvard:
                    //your code here
                    break;

            }
            return true;
        }
    });

    popup.show();
}

Upvotes: 3

Related Questions