android菜单图标大小

don*_*gcn 8 icons android menu menuitem

我需要以编程方式设置菜单图标(不是通过布局文件),还需要从file:/// android_asset /(不加载为已编译的Drawable)加载图标文件.我发现显示图标的大小相对较小.它看起来像android调整大小或其他东西,我不想用代码实现相同的效果.

正如你在附加的屏幕截图中看到的那样,菜单"globe-36","globe-48"和"globe-72"使用代码填充,并且它们的图像是36x36,48x48和72x72 :(这是我在我的应用程序中加载我的图标的方式,我必须)

            MenuItem mi = menu.add(Menu.NONE, i++, i++, icon);
            Drawable d = Drawable.createFromStream(getAssets().open(icon + ".png"), icon);
            mi.setIcon(d);
Run Code Online (Sandbox Code Playgroud)

并且,菜单"globe-aset"和"barcode-asset"填充如下:

    MenuItem mi = menu.add(Menu.NONE, i++, i++, "globe-asset");
    mi.setIcon(R.drawable.globe);
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Kur*_*wig 10

菜单图标的大小为:

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

因为你的globe-asset大约是globe-48的两倍-我假设你的截图来自xhdpi设备,它希望菜单图标为96x96.