Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android custom Overflow-menu (Without actionbar and no menubutton)

In my application I have made my own Actionbar, and it works very well.

I would however like to use the behaviour of the overflow buttons on ICS-devices with no menu-button.

Is there a way to implement a custom Overflowbutton in ICS that is separate from the Actionbar?

Thanks!

like image 777
DagW Avatar asked May 15 '12 13:05

DagW


1 Answers

userSeven7s mostly has it with the ListPopupWindow, but an even better fit in this case is the PopupMenu, which allows you to inflate a standard menu.xml. You can place your own View or Button in the upper right and in the onClick handler create and show a PopupMenu.

An example can be found in ApiDemos > Views > Popup Menu . Specifically PopupMenu1.java:

public void onPopupButtonClick(View button) {
    PopupMenu popup = new PopupMenu(this, button);
    popup.getMenuInflater().inflate(R.menu.popup, popup.getMenu());

    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            Toast.makeText(PopupMenu1.this, "Clicked popup menu item " + item.getTitle(),
                Toast.LENGTH_SHORT).show();
            return true;
        }
    });

    popup.show();
}
like image 135
Kevin TeslaCoil Avatar answered Oct 02 '22 20:10

Kevin TeslaCoil