Skip to content Skip to sidebar Skip to footer

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 the

Solution 1:

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:

publicvoidonPopupButtonClick(View button) {
    PopupMenupopup=newPopupMenu(this, button);
    popup.getMenuInflater().inflate(R.menu.popup, popup.getMenu());

    popup.setOnMenuItemClickListener(newPopupMenu.OnMenuItemClickListener() {
        publicbooleanonMenuItemClick(MenuItem item) {
            Toast.makeText(PopupMenu1.this, "Clicked popup menu item " + item.getTitle(),
                Toast.LENGTH_SHORT).show();
            returntrue;
        }
    });

    popup.show();
}

Solution 2:

Have you looked at ActionBar Sherlock? ABS provides action bar support for all devices running android 2.1 and above. The ActionBarCompat sample is very limited and does not support overflow menus on older devices. Be sure to use the Theme.Sherlock.ForceOverflow theme to enable overflow.

http://actionbarsherlock.com/

You could also modify the QuickAction library to do what you want.

https://github.com/lorensiuswlt/NewQuickAction

Solution 3:

You could slide/scroll your action bar to let access to more options. Put your action bar in a HorizontalScrollView.

You might also want to take a look at PopupWindow class here, and ListPopupWindow documentation here.

Post a Comment for "Android Custom Overflow-menu (without Actionbar And No Menubutton)"