Actionbar popup menu item not visible

346 views Asked by At

I have implemented popup menu in button onClick, with AppCompact theme I can get the menu overflow with empty items in menu. please help me on this

OptionMenuBtn = (ImageButton) v.findViewById(R.id.three_dot);
        OptionMenuBtn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated m// openOptionsMenu();
                showPopup(v);


            }
        });


    public void showPopup(View v) {

        PopupMenu popup = new PopupMenu(MainActivity.this, v);
        MenuInflater inflater = popup.getMenuInflater();
        inflater.inflate(R.menu.action_menu, popup.getMenu());
        popup.show();
    }

enter image description here

1

There are 1 answers

0
Raut Darpan On BEST ANSWER

this should be the Xml file :

<?xml version="1.0" encoding="utf-8"?><menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:id="@+id/menu_edit"
    android:title="@string/menu_edit" />
<item
    android:id="@+id/menu_block"
    android:title="@string/menu_deactivate" /></menu>

and the code in activity on your onclick

  PopupMenu popupMenu = new PopupMenu(YourActivity.this, view);
            popupMenu.setOnMenuItemClickListener(YourActivity.this);
            popupMenu.inflate(R.menu.menu_import_export);
            popupMenu.show();

and implements :

  @Override
public boolean onMenuItemClick(MenuItem item) {
    switch (item.getItemId()) {
       case R.id.menu_edit:
           //TODO
            return true;
        case R.id.menu_block:
        //TODO 
            return true;

    }
    return false;
}