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 36x36, 48x48 and 72x72 : (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);
On Android devices, launcher icons are generally 96×96, 72×72, 48×48, or 36×36 pixels (depending on the device), however Android recommends your starting artboard size should be 864×864 pixels to allow for easier tweaking.
The sizes of menu icons are:
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 96x96.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With