I need to set the menu icon programmatically (Not through a layout file), and also I need to load the icon file from file:///android_asset/ (Not load as a compiled Drawable). I found the size of the displayed icon is relatively smaller. It looks like android resize it or something, and I do not want to achieve the same effect with out code.
As you can see in the in the attached screen shot, the menu “globe-36”, “globe-48” and “globe-72” is populated using code like, and their image are 36×36, 48×48 and 72×72 : (This is the way I load my icon in my app, I have to)
MenuItem mi = menu.add(Menu.NONE, i++, i++, icon); Drawable d = Drawable.createFromStream(getAssets().open(icon + ".png"), icon); mi.setIcon(d);
And, the menu “globe-aset” and “barcode-asset” are populated like:
MenuItem mi = menu.add(Menu.NONE, i++, i++, "globe-asset"); mi.setIcon(R.drawable.globe);
The sizes of menu icons are:
- ldpi: 36×36
- mdpi: 48×48
- hdpi: 72×72
- xhdpi: 96×96
- xxhdpi: 144×144
as your globe-asset is about twice as large as the globe-48 I assume that your screenshot is from an xhdpi device which expects the menu icons as 96×96.