Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

icon in menu not showing in android

Tags:

android

I want to add menu handler to my project. I read http://developer.android.com/guide/topics/ui/menus.html too, its very simple but the icon is not shown. I am very confused. I even added a menu item programmatically.

My code is:

@Override public boolean onCreateOptionsMenu(Menu menu) {     menu.add(0, 0, 0, "Quit").setIcon(R.drawable.ic_launcher);     getMenuInflater().inflate(R.layout.menu, menu);     return true; } 

and in xml:

<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android">     <!-- Single menu item           Set id, icon and Title for each menu item      -->     <item android:id="@+id/menu_bookmark"            android:icon="@drawable/update"           android:title="@string/Update" />  </menu> 
like image 767
Shayan Pourvatan Avatar asked Nov 03 '13 07:11

Shayan Pourvatan


People also ask

How do I show the menu icon on Android?

Click res → New → Vector Asset . Choose the icon that you want by clicking on the android icon, click “Next” button and then click “Finish”. 6- Now we can add android menu items with icons, we will have 4 menu items. 1 menu item will be the root while the other 3 menu items will be grouped under a single Menu .


2 Answers

After Long try i found below solution which might help others to save there time. Basically, the solution provided by "lbarbosa", i like to thanks to him sincerely.

Tried this based on the previous answers and it works fine, at least with more recent versions of the support library (25.1):

@Override public boolean onCreateOptionsMenu(Menu menu) {     getMenuInflater().inflate(R.menu.menu_main, menu);      if(menu instanceof MenuBuilder){         MenuBuilder m = (MenuBuilder) menu;         m.setOptionalIconsVisible(true);     }      return true; } 
like image 160
Pranob Avatar answered Oct 26 '22 23:10

Pranob


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.

like image 44
Szymon Avatar answered Oct 26 '22 23:10

Szymon