dongshengcn
dongshengcn

Reputation: 6504

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

Upvotes: 9

Views: 27458

Answers (1)

Kurt Huwig
Kurt Huwig

Reputation: 1013

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.

Upvotes: 12

Related Questions