9

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

David Snabel-Caunt
  • 57,804
  • 13
  • 114
  • 132
dongshengcn
  • 6,434
  • 7
  • 35
  • 44

1 Answers1

12

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.

Kurt Huwig
  • 983
  • 11
  • 11
  • For newer info, look here https://stackoverflow.com/questions/13639263/whats-the-correct-size-icon-for-drawable-xxhdpi – Justin May 22 '15 at 04:05