Android MipMap - 如何在 XML 中创建图像资源

Android MipMap - How to create image resources in XML

我注意到 Android Studio 在项目目录中有 "mipmap" 个文件夹。据我了解,为了确保我们在所有设备(应用内图标)上具有图像资源的一致性,我们应该使用 XML 格式的图像资源,如下所示:

    <!-- drawable/numeric-1-box.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportHeight="24"
    android:viewportWidth="24">
    <path
        android:fillColor="#757575"
        android:pathData="M14,17H12V9H10V7H14M19,3H5A2,2 0 0,0 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V5A2,2 0 0,0 19,3Z" />
</vector>

我一直在使用 Material Design Icons 网站获取 XML 格式的大部分常用图标。但是,我该如何着手创建这样的图标呢?到目前为止,我一直在从上面显示的站点下载它们。有没有我可以用来将图像导出为这些格式 (XML) 的工具?这样做的程序是什么? Photoshop、Illustrator 或其他图像转换网络工具?将不胜感激有关如何创建这些图像的任何帮助。

I've noticed for a while now that Android Studio has "mipmap" folders in the project directory.

请注意,这与您问题的其余部分无关。矢量绘图将进入 res/drawable-nodpi/,而不是 mipmap 目录。

From what I understand, in order to make sure we have consistency of image resources across all devices (in-app icons) we should have image resources in XML format such as the one shown below:

仅当您的 minSdkVersion 为 21 或更高时,或者如果您使用的库提供 VectorDrawable 的向后移植。 Android 1.0 到 4.4 不支持 <vector> 可绘制对象。

how do I go about creating icons like these?

我将从创建代表您的图标的 SVG 文件开始。您可以使用 Inkscape 等工具在本地使用 SVG,其他图形工具(例如 Adob​​e Illustrator)可以导出为 SVG。您在 XML 中看到的 <path> 是基于 SVG 路径规范的。

从那里,您可以创建 <vector> 可绘制对象 manually or use tools 以执行 SVG->VectorDrawable 转换。