0

I'm a using a GridView and a PopupMenu for every item of the GridView. Unfortunately the popup appears below or over the item that is clicked. I would like it to appear on the center of the screen horizontally and vertically.

PopupMenu popupMenu = new PopupMenu(wrapper, v);
popupMenu.getMenuInflater().inflate(R.menu.item_gridview_menu, popupMenu.getMenu());

I have tried setting the gravity to center like this

PopupMenu popup = new PopupMenu(this, v,Gravity.CENTER);   

but it just centers the popup over the item that is clicked. Also I have styled the popup with:

<style name="PopupMenu" parent="@android:style/Widget.PopupMenu">
    <item name="android:popupBackground">@android:color/white</item>
    <item name="android:gravity">center_horizontal</item>
    <item name="android:textColor">@color/white</item>
    <item name="android:background">@color/colorPrimary</item>
</style>

but that didn't help either. Any ideas?

Kostas St
  • 3
  • 1
  • 8

1 Answers1

0

Had task like this one and made custom AlertDialog for this.

final Dialog dialog = new Dialog(context);
        dialog.setContentView(R.layout.custom); // Your custom XML
        dialog.setTitle("Title...");

        // set the custom dialog components - text, image and button
        TextView text = (TextView) dialog.findViewById(R.id.text);
        text.setText();

        ImageView image = (ImageView) dialog.findViewById(R.id.image);
        image.setImageResource();

        Button dialogButton = (Button) 
        dialog.findViewById(R.id.dialogButtonOK);
        dialogButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        dialog.show();
Dmitry Ushkevich
  • 392
  • 2
  • 14