当我在AndroidStudio中运行Inspect Code时,我会得到5倍的警告"图标的大小不正确";警告指向5种不同分辨率的ic_launcher_foreground.png
文件。
../drawable-mdpi/ic_launcher_foreground.png: 108x108 px
../drawable-hdpi/ic_launcher_foreground.png: 162x162 px
../drawable-xhdpi/ic_launcher_foreground.png: 216x216 px
../drawable-xxhdpi/ic_launcher_foreground.png: 324x324 px
../drawable-xxxhdpi/ic_launcher_foreground.png: 432x432 px
就像这里指定的一样:https://developer.android.com/guide/practices/ui_guidelines/icon_design_adaptive
在Android 7.1(API 25级(及更早版本中,启动器图标的大小为48 x 48 dp。您现在必须使用以下指南调整图标层的大小:
两层的尺寸必须为108 x 108 dp。
图标的内部72 x 72 dp显示在遮罩视口中。
该系统在4个侧面中的每个侧面上都保留了外部18dp,以产生有趣的视觉效果,例如视差或脉冲。
除此之外,我提供了同样大小正确的老式图标:
../midmap-mdpi/ic_launcher.png: 48x48 px
../midmap-hdpi/ic_launcher.png: 72x72 px
../midmap-xhdpi/ic_launcher.png: 96x96 px
../midmap-xxhdpi/ic_launcher.png: 144x144 px
../midmap-xxxhdpi/ic_launcher.png: 192x192 px
../midmap-v26/ic_launcher.xml
在midmap-v26/ic_launcher.xml
中,我指定ic_launcher_foreground.png
仅用于Android 8+。。。这是它唯一被引用的地方。
警告的详细信息表明,新图标的大小应该是旧的/更小的。例如mdpi:
"drawable mdpi/ic_launcher_foregraund.png"的图标大小不正确:应为48x48,但为108x108
我看不出我做错了什么。当我将应用程序加载到不同的手机上时,图标看起来不错,所以这可能是一个假阳性。然而,我不想取消警告,因为它可能有助于未来的更改。
来自我的build.gradle,如果有趣的话:
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
minSdkVersion 21
targetSdkVersion 28
}
在清单中
android:icon="@mipmap/ic_launcher"
在此处添加您的图标图像在这种情况下,您不需要调整图标大小48x48
72x72
它将自动生成。