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!

2
  • 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. Commented May 15, 2012 at 13:23
  • Have you looked at developer.android.com/resources/samples/ActionBarCompat/…? Commented May 17, 2012 at 16:57

3 Answers 3

19
+50

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();
}
Sign up to request clarification or add additional context in comments.

3 Comments

Perfect! Is it availible with the compability package?
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 developer.android.com/reference/android/view/… .
but by using popup menu you can not add icon
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

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.