使用什么 mipmap 或 drawable

What to use mipmap or drawable

我是新 android 用户并使用 Android Studio 1.3。我想创建简单的启动画面,为此,我创建了不同的可绘制文件夹,用于存储启动画面背景图像。我从各自的 mipmap 文件夹中复制所有 ic_launcher,并将它们粘贴到各自的可绘制文件夹中。并更改清单 also.as、

中的图标路径
 <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">

到,

 <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

但这给我的错误是,

Error:(14, 24) No resource found that matches the given name (at 'icon' with value '@mipmap/ic_launcher').

我的问题是,

  1. 我们总是只需要将应用程序图标存储在 mipmap 文件夹中吗?为什么?

  2. 什么时候使用 mipmap 和 drawable?

Android 团队将 mipmap 用于启动器图标描述为最佳实践。您获得的优势是您可以将所有设备密度的资源保存在 mipmap 文件夹中,然后从可绘制文件夹中删除与特定用户设备密度无关的其他资源。

例如,用户拥有分类为 xxhdpi 的设备。您的 apk 中所有其他密度(例如 xxxhdpi)的可绘制资源不是必需的,可以删除。

reference

mipmap 文件夹仅用于放置您的 app/launcher 图标(显示在主屏幕上)。 您使用的任何其他可绘制资源都应像以前一样放置在相关的可绘制文件夹中。

根据这篇 Google 博文和 Android 开发人员的推荐:

It’s best practice to place your app icons in mipmap- folders (not the drawable- folders) because they are used at resolutions different from the device’s current density.