开发者

Shortcut icon too small from assets directory

This is the craziest issue. I am loading custom icons from the assets directory for use with my application. The application loads the custom icon and makes a shortcut on the desktop. All of the icons are 48x48 png files.

On the Android 2.1 and 2.2 emulator this works perfect. On the Droid X (Android 2.2) the icons show up smaller than 48x48.

Now for the kicker, if I move one of the icons to the drawable directory and load it from there it shows up correctly.

Any ideas what the problem could be with the droid x?

Is there any way to get a list of all drawables? If there is I c开发者_运维技巧ould just put all my icons in the drawables directory, albeit a little ugly to dump 100 icons in there.

My code for loading the icons is pretty standard:

        AssetManager assets = context.getAssets();
        InputStream inputStream = assets.open("icons/"+ name);
        if (inputStream != null)
        {
            Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
            if (bitmap != null)
            {
                return bitmap;
            }
        }


One thing to mention here is when you said it worked okay on 2.1, 2.2 emulators.. what was the density of the emulators used. Density has a huge impact on how images are displayed.

Another point, according to how android handles images, the attributes of small/normal/large/xlarge screens and ldpi/mdpi/hdpi/xdpi are applied to assets in res and thus drawable folders. It doesnt apply to assets folder.

What I am trying to say is to read up on how Android displays assets and play around with playing your icon in res folder instead of assets folder. You will find the solution, and also increase your Android knowledge.


See this answer on how to iterate through all drawables in R.

This is the relevant line:

Field[] drawables = android.R.drawable.class.getFields();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜