Get correct Laucher icon size on Android

折月煮酒 提交于 2019-12-07 20:52:24

问题


I am working on an app which is able to add shortcuts icons to the homescreen. What is the correct icon size for Android tablets? (Or better said, how to get it at runtime?) It seems to differ from what is written on this page. I have switch on DisplayMetrics.densityDpi and change the icon size accordingly. But it does not work for all devices..Gnex seems to be ok, but my Galaxy Tab while beeing DisplayMetrics.DENSITY_MEDIUM device displays only 48x48px icon (as it is in guidelines), but usual launcher icons are 72x72 pixels and not 48x48 - it differs from guidelines? Is it possible that it is related to TouchWiz UI and thus it differs from pure Android? Or where is the problem? Also good to note, that apps itself displays correct launcher icon (it takes the icon from hdpi folder), but at runtime it looks like it is mdpi device:/ Thanks


回答1:


Android tablets looks one bucket up, when looking for launcher icon..That means mdpi device will actually look into hdpi folder.. This code returns correct size for launcher icons

 ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
 int iconSize = am.getLauncherLargeIconSize();

Answer is based on this g+ post by Nick Butcher




回答2:


best thing you use the android assets studio tool for this task .

it will automatically create the correct sizes and put them in the correct folders .



来源:https://stackoverflow.com/questions/14084259/get-correct-laucher-icon-size-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!