3

I have an Android app on the play store (Raleigh Nights) and it has just been brought to my attention that the drawable icons in my overflow button are not showing, although the text is showing properly. Everything is showing properly on 4.3 and I have no idea what may cause the difference. When I debug using an emulator it seems to set MenuItem icon and doesn't throw any exceptions. I've spent hours trying to figure out what is going on to no avail. Again, it works in older versions, but does not show the icon in 4.4.2 (KitKat). It also crashes on some 4.4.2 phones although I can't get it to crash on the emulator.

I have the target set to 19. minVersion = 11;

<uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="19" />

I'm also going to include the menu button that I have to see if that helps.

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <!-- Will always be in the overflow -->
    <item android:id="@+id/menu_drink_specials"
          android:title="@string/drinks"
          android:icon="@drawable/added"
          android:showAsAction="never"/>
    <item android:id="@+id/menu_food_specials"
          android:title="@string/food"
          android:icon="@drawable/added"
          android:showAsAction="never"/>
    <item android:id="@+id/menu_events"
          android:title="@string/events"
          android:icon="@drawable/added"
          android:showAsAction="never"/>
    <item android:id="@+id/sort_location"
          android:title="@string/sortLocation"
          android:icon="@drawable/added"
          android:showAsAction="never"/>
</menu>

Has anyone else run across this problem? It seems odd that it works so well in the the other versions and isn't throwing any errors up.

Thanks for your time, Mike

michaelp
  • 353
  • 6
  • 24

5 Answers5

2

Are you certain that you have icons showing next to items in the overflow menu? This is intentionally not allowed:

Displaying icon for menu items of Action Bar in Honeycomb android 3.0

It seems like there are several hacks to make something like this work. Maybe you're using one of them and it's what's causing your crash.

However if you want full control over this, it may be best to extend PopupWindow and simply inflate whatever layout you'd like into it. You could then create a 'fake' overflow button in the action bar and configure the PopupWindow to display beneath it.

Community
  • 1
  • 1
Kyle Ivey
  • 5,992
  • 1
  • 23
  • 35
  • So I am positive that the icons are showing up next to items in the overflow menu. I did add a hack to let that happen and they were showing up correctly. What I ended up going with was the fake overflow button and then inflating below. Thank you for the suggestion! – michaelp Jul 01 '14 at 15:02
1

The way you have your items set up with android:showAsAction="never" will never put icons into the overflow menu. Android, by default, does not allow this. The only way to display icons is to make showAsAction equal to always or ifroom and also have android:icon set. Your app will most likely look fine without the icons in the overflow menu.

Andrew Quebe
  • 2,263
  • 5
  • 25
  • 53
0

Try to put this code on your activity.

@Override
public boolean onMenuOpened(int featureId, Menu menu)
{
    if(featureId == Window.FEATURE_ACTION_BAR && menu != null){
        if(menu.getClass().getSimpleName().equals("MenuBuilder")){
            try{
                Method m = menu.getClass().getDeclaredMethod(
                    "setOptionalIconsVisible", Boolean.TYPE);
                m.setAccessible(true);
                m.invoke(menu, true);
            }
            catch(NoSuchMethodException e){
                Log.e(TAG, "onMenuOpened", e);
            }
            catch(Exception e){
                throw new RuntimeException(e);
            }
        }
    }
    return super.onMenuOpened(featureId, menu);
}
Haresh Chhelana
  • 24,720
  • 5
  • 57
  • 67
0

add these attributes to the menu tag and try

xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
Sainath Patwary karnate
  • 3,165
  • 1
  • 16
  • 18
0

You configured "android:showAsAction="never"" and this way and will never display the icons into the overflow menu.

Try change your code like this

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <!-- Will always be in the overflow -->
    <item android:id="@+id/menu_drink_specials"
          android:title="@string/drinks"
          android:icon="@drawable/added"
          android:showAsAction="ifRoom"/>
    <item android:id="@+id/menu_food_specials"
          android:title="@string/food"
          android:icon="@drawable/added"
          android:showAsAction="ifRoom"/>
    <item android:id="@+id/menu_events"
          android:title="@string/events"
          android:icon="@drawable/added"
          android:showAsAction="ifRoom"/>
    <item android:id="@+id/sort_location"
          android:title="@string/sortLocation"
          android:icon="@drawable/added"
          android:showAsAction="ifRoom"/>
</menu>
rochasdv
  • 539
  • 2
  • 8
  • 21