5

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!

DagW
  • 955
  • 1
  • 15
  • 28
  • To clarify: I want to get rid of the black bar on the bottom with three dots, and istead implement my own version in my custom actionbar. – DagW May 15 '12 at 13:23
  • Have you looked at http://developer.android.com/resources/samples/ActionBarCompat/index.html? – techi.services May 17 '12 at 16:57

3 Answers3

19

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();
}
Kevin TeslaCoil
  • 10,037
  • 1
  • 39
  • 33
  • Perfect! Is it availible with the compability package? – DagW May 23 '12 at 18:41
  • 1
    No and I imagine it would be rather difficult to backport. But I'd actually recommend just utilizing the existing menu button on devices that have it (all Android 2.x) and just using the popup menu on devices without a menu button, you can detect this with http://developer.android.com/reference/android/view/ViewConfiguration.html#hasPermanentMenuKey() . – Kevin TeslaCoil May 24 '12 at 06:28
  • but by using popup menu you can not add icon – Deepak Goel Jun 18 '12 at 03:47
0

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

Frohnzie
  • 3,559
  • 1
  • 21
  • 24
0

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.

Ron
  • 24,175
  • 8
  • 56
  • 97