PopupMenu equivalente en ActionBarSherlock

¿Qué es Popupmenu equivalent in ActionBarSherlock? I can't seem to find it. Its API 11, why is it absent?

preguntado el 25 de agosto de 12 a las 20:08

AFAIK PopupMenu is not required for an action bar. ActionBarSherlock isn't a backport of todo. -

Also, I see at least one (non-general-purpose) backport of PopupMenu in the first page of a Google search for android popupmenu backport, so you might consider just grabbing the AOSP source and trying to backport it yourself. -

3 Respuestas

La clase MenuPopupHelper pretty much does the job. I didn't find an easy way to listen for Item Clicks though, so I implemented this class that derives from MenuPopupHelper:

public class MenuPopup extends MenuPopupHelper {

    OnMenuItemClickListener onMenuItemClickListener;

    public MenuPopup(Context context, MenuBuilder menu, View anchorView) {
        super(context, menu, anchorView);

    public void setOnMenuItemClickListener(
            OnMenuItemClickListener onMenuItemClickListener) {
        this.onMenuItemClickListener = onMenuItemClickListener;

    public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {
        super.onItemClick(parent, view, position, id);
        if (onMenuItemClickListener != null)

    public interface OnMenuItemClickListener{
        public void onMenuItemClick(int itemID);

respondido 29 mar '14, 16:03

This solution is not perfect as the anchorView view object must implement View_OnAttachStateChangeListener interface that required by AcctionBarSherlock. - Sam Lu

It's quite easy to make a View implementando el View_HasStateListenerSupport interface. You can find a example of implementation here: github.com/JakeWharton/ActionBarSherlock/blob/master/… - ol_v_er

Adicional PopupMenu in AcciónBarSherlock.

Styling of the PopupMenu -

<item name="popupMenuStyle">@style/PopupMenu.MyAppTheme</item>      

<style name="PopupMenu.MyAppTheme" parent="@style/Widget.Sherlock.ListPopupWindow">
    <item name="android:popupBackground">@android:color/white</item>

respondido 05 nov., 13:05

I'm working on this currently. I did what was suggested by CommonsWare about backporting it. I basically took the PopupMenu.java source code and replaced the package imports with the actionbarsherlock equivalents. It seems to work fine on the gingerbread and ics devices I tested on. The catch though is in actionbarsherlocks MenuPopupHelper class I had to comment lines referencing View_HasStateListenerSupport like:


for some reason. If I didn't I would get a ClassCastException:

E/AndroidRuntime(9197): FATAL EXCEPTION: main E/AndroidRuntime(9197): java.lang.ClassCastException: android.widget.Button cannot be cast to com.actionbarsherlock.internal.view.View_HasStateListenerSupport E/AndroidRuntime(9197): at com.actionbarsherlock.internal.view.menu.MenuPopupHelper.tryShow(MenuPopupHelper.java:121) E/AndroidRuntime(9197): at com.actionbarsherlock.internal.view.menu.MenuPopupHelper.show(MenuPopupHelper.java:102)

I'm unsure if commenting out that listener could cause problems for other classes that utilize MenuPopupHelper or why they are causing this exception (maybe a bug). But I thought I would share what I tried, so it may help anyone looking into this.

Respondido 26 Oct 12, 03:10

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.