8

I am trying to show icons with overflow menu with below codes

MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.my_menu,menu);

if(menu instanceof MenuBuilder){
    MenuBuilder menuBuilder = (MenuBuilder) menu;
    menuBuilder.setOptionalIconsVisible(true);
}

It gives me this error

menuBuilder.setOptionalIconsVisible can only be called from within the same library group

on line

menuBuilder.setOptionalIconsVisible(true);

I know I can suppress it for ignore but I want know why its coming and there any another way to fix it ?

Thanks

John
  • 10,165
  • 5
  • 55
  • 71
Priyanka
  • 137
  • 2
  • 7

1 Answers1

-5

Edit

Ok, after investigating more on the subject this seems to be a bug as stated in comment and answers to this question and should be safe to suppress it. It may be fixed in one of the next releases of support libraries.


OLD ANSWER

Why not make menu items visible in XML? Use attribute android:showAsAction. There are several values available: ifroom | always | collapseActionView | never | withText - read more.

For instance if you want to always show first item and show second item if there is room for it:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <item android:id="@+id/item_id1"
        android:icon="@drawable/ic_icon1"
        app:iconTint="@color/white"
        app:showAsAction="always"
        android:title="First item"/>

    <item android:id="@+id/item_id2"
        android:icon="@drawable/ic_icon2"
        app:iconTint="@color/white"
        app:showAsAction="ifRoom"
        android:title="Second item"/>
</menu>
Variag
  • 1,056
  • 10
  • 25
  • 1
    The question is about showing icons in the overflow menu. This does not awnser that at all – svn Mar 27 '18 at 07:43