Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android menu icon size

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);

enter image description here

like image 770
dongshengcn Avatar asked Apr 05 '11 21:04

dongshengcn


People also ask

What size are Android app icons?

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.


1 Answers

The sizes of menu icons are:

  • ldpi: 36x36
  • mdpi: 48x48
  • hdpi: 72x72
  • xhdpi: 96x96
  • xxhdpi: 144x144

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.

like image 165
Kurt Huwig Avatar answered Sep 21 '22 18:09

Kurt Huwig