0

I am aware of the answer posted here:

icon in menu not showing in android

However, the question then remains: how then does Google want me to indicate that a MenuItem has 'More' when showing a popupmenu with a submenu like this:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:title="Genres" android:icon="@android:drawable/ic_menu_more">
        <menu xmlns:android="http://schemas.android.com/apk/res/android">
            <item android:id="@+id/genredrama" android:title="Drama" />
            <item android:id="@+id/genrefamily" android:title="Family" />
            <item android:id="@+id/genrehorror" android:title="Horror" />   
        </menu>
   </item>
<item  android:title="All" />
<item android:title="Top Picks" />
<item android:title="Best" />   
</menu>

How can I make the icon:

ic_menu_more

appear in the Genres MenuItem? I know this is a design decision by google, but what is proper way now to indicate the menutItem has a submenu?

Community
  • 1
  • 1
JohnRock
  • 6,795
  • 15
  • 52
  • 61
  • It's usually not good design to have submenus when using the standard Android menu/overflow menu. Did you consider using an action instead? Or maybe the navigation drawer? – ashishduh May 19 '14 at 17:23
  • It seems to me that a PopupMenu is a standard Android feature that supports submenus: https://developer.android.com/reference/android/support/v7/widget/PopupMenu.html So why would it be 'bad design' to use a feature that the SDK provides for? There are certainly cases where this might be appropriate, if not then why does submenu functionality exist at all? – JohnRock May 19 '14 at 17:49

2 Answers2

0

I think you have to set this property in your item tag:

android:showAsAction="always" //this will force to show menu item
Illegal Argument
  • 10,090
  • 2
  • 44
  • 61
  • That does not solve the issue. I believe that only relates to showing the item in the Action Bar. In my example, the submenu is not related to the action bar. – JohnRock May 19 '14 at 17:44
0

I found the solution to this problem by modifying the solution in this answer: https://stackoverflow.com/a/22668665/3612509

The following code displays the icon next to the 'Genres' menu as desired:

PopupMenu popupMenu = new PopupMenu(this, view);
        popupMenu.inflate(R.menu.menu_movies);        

        try{
            Method m = popupMenu.getMenu().getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE);
            m.setAccessible(true);
            m.invoke(popupMenu.getMenu(), true);
        }
        catch(NoSuchMethodException e){
            Log.e("DEMO", "onMenuOpened", e);
        }
        catch(Exception e){
            throw new RuntimeException(e);
        }
Community
  • 1
  • 1
JohnRock
  • 6,795
  • 15
  • 52
  • 61