应用程序图标:为什么我会从Lint收到“图标尺寸不正确”的警告?

时间:2018-12-06 11:18:46

标签: android

当我在AndroidStudio中运行检查代码时,我收到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个面的每一侧保留外部18 dp,以创建有趣的视觉效果,例如视差或脉冲。

  •   

最重要的是,我还提供了正确尺寸的旧图标:

../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_foreground.png”的图标大小不正确:预期为48x48,但为108x108

我在这里看不到我做错了什么。当我将应用程序加载到其他手机上时,该图标看起来不错,因此这可能是误报。但是,我不想抑制该警告,因为它可能对将来的更改有所帮助。

如果有意思,请从我的build.gradle中获取

compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
    minSdkVersion 21
    targetSdkVersion 28
}

1 个答案:

答案 0 :(得分:0)

在清单中

android:icon="@mipmap/ic_launcher"

在此处添加您的图标图片 在这种情况下,您无需调整图标大小的大小48x48 72x72 它将自动生成。