Icon in Menu Not Showing in Android

icon in menu not showing in android

If you're running your code on Android 3.0+, the icons in the menu are not shown by design. This is a design decision by Google.

You can read more about it in this on Android developers blog.

Menu icon doesn't show up

Wrap your items inside <menu>and add app:showAsAction="always" to your parent item.

Updated menu :

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

<item android:id="@+id/action_notification1"
android:icon="@drawable/ic_more"
app:showAsAction="always"
android:title="action_notification">
<menu>
<item android:id="@+id/action_share_us"
android:icon="@drawable/ic_share"
android:title="@string/share_us" />
<item android:id="@+id/action_rate_us"
android:icon="@android:drawable/ic_menu_info_details"
android:title="@string/rate" />
<item android:id="@+id/action_about"
android:checked="false"
android:icon="@drawable/ic_about"
android:title="@string/about" />
</menu>
</item>

</menu>

And to show menu below toolbar you need to provide actionOverflowMenuStyle for your style.
For this please see : https://stackoverflow.com/a/34288434/3552066

Icons on a context menu are not showing?

If you're running your code on Android 3.0+, the icons in the menu are not shown by design. This is a design decision by Google.

But if you really want to show icons, you can use the code:

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
try {
Field field = menu.getClass().getDeclaredField("mOptionalIconsVisible");
field.setAccessible(true);
field.setBoolean(menu, true);
} catch (Exception e) {
e.printStackTrace();
}
return super.onPrepareOptionsMenu(menu);
}

It uses reflection and sets the icons visible. I tested and here is the result:

Sample Image

Android Toolbar Popup menu not showing icons

I found this solution: https://stackoverflow.com/a/30337653/197127. Basically, overriding a method and it does not break the device menu button or the overflow.
Thanks to all.

Android options menu icon won't display

On Android 3.0+, the preferred approach for the options menu (a spillover menu in the action bar) will not show icons. If you have android:targetSdkVersion="11" or higher, icons will never show up in menus on Android 3.0+. The icons will show up if you promote an options menu item to be a toolbar button, and the icons will show up on Android 1.x/2.x devices.

Android: Icon in menu not showing like it should

Icons are supposed to be all one color but you actually have two colors in your image.

See how the side of the triangle at the upper left is green in your image but white in the menu? Your green pixels are being tinted white, the same color as your background, so you don't see them.

If you really want a "negative" image like this, my recommendation would be to take all the green pixels that are surrounded by white pixels and make them transparent. That way the background green will show through and it will look like you expect.

While you're at it, you might as well change those upper triangle pixels from green to white, since they will be tinted white anyways.

menu Item not showing if actionLayout is set

As you have already defined app:actionLayout in your menu item of your actionbar_sync.xml menu file, the default android:icon attribute won't work. Therefore, the solution is to add your sync icon using an ImageView along with your ImageView with badge in your actionbar_badge_layout.xml file and remove android:icon attribute from your menu item.

actionbar_sync.xml

<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
android:id="@+id/action_sync"
android:title="Sync"
app:actionLayout="@layout/actionbar_badge_layout"
app:showAsAction="always"
/>
</menu>

actionbar_sync.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
style="?attr/actionButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:focusable="true"
>

<!-- Badge -->
<ImageView
android:id="@+id/img_badge_sync"
android:layout_width="12dp"
android:layout_height="12dp"
android:src="@drawable/badge_noty" />

<!-- Sync image -->
<ImageView
android:id="@+id/icon_sync"
android:layout_width="32dp"
android:layout_height="32dp"
android:src="@drawable/ic_sync" />

</FrameLayout>


Related Topics



Leave a reply



Submit