【问题标题】:Why does Android Studio create the ic_launcher_foreground in res/drawable-v24 and the ic_launcher_background.xml in res/drawable?为什么 Android Studio 在 res/drawable-v24 中创建 ic_launcher_foreground 而在 res/drawable 中创建 ic_launcher_background.xml?
【发布时间】:2019-12-11 02:28:27
【问题描述】:

首先

我注意到在 Android Studio 中创建新项目时,它会生成带有 ic_launcher_foreground.xml 图标的 drawable-v24 文件夹。

我的问题是:

  1. 如果 vector drawables 是在 v24 之前引入的,那么为什么它将矢量资源放在 drawable-v24 而不是 drawable-v21 文件夹中?

其次

另一个生成的资产是ic_launcher_background.xml,它是在res/drawable 文件夹中创建的,后来被mipmap-anydpi-v26/ic_launcher.xml 引用。

  1. 如果它只在 API v26+ (adaptive icons) 中使用,那么为什么它是在 res/drawable 文件夹中创建而不是在 res/drawable-v24res/drawable-v26 中创建的?是不是因为 mipmap 文件夹的某些性质?

【问题讨论】:

  • 你找到这个答案了吗?

标签: android android-studio icons android-vectordrawable adaptive-icon


【解决方案1】:

VectorDrawable 功能在某种程度上集成在 API-24 中,尽管它是从 API-21 引入的。我认为 Google 的开发人员认为 API-24+ 对于自适应图标来说是理想的或稳定的。

比如Nick Butcher(Android设计师+开发者@Google)在他的文章中说:Using vector assets in Android apps(Dec 11, 2018),

  • nonZero 和 evenOdd 路径 fillTypes — 定义形状内部的两种常用方法,常用于 SVG(在 API 24 中将 evenOdd 添加到平台实现中)
  • 渐变和 ColorStateList 填充/描边(在 API 24 中添加到平台实现)

关于ic_launcher_background,仅引用自mipmap-anydpi-v26/ic_launcher.xmlmipmap-anydpi-v26/ic_launcher_round.xml。我认为只是没有必要阻止直接引用它(它已经通过将ic_launcher.xmlic_launcher_round.xml 放在mipmap-anydpi-v26 文件夹中来阻止)。应该没有这么多,深刻的含义。

【讨论】:

    【解决方案2】:

    codelab 回答您的问题。

    根据您应用的最小 SDK,您可能会注意到前景资源位于 drawable-v24 文件夹中,而背景资源位于 drawable 文件夹中。原因是前景资源包含渐变,从 Android 7.0 版本开始就可以使用(也称为 API 版本 24,因此是 -v24 资源限定符)。背景资源不包含渐变,因此可以放在基础可绘制文件夹中。

    附带说明一下,虽然我们一般不会将ic_launcher_background.xml 用于应用图标以外的任何用途,但它只是一个矢量可绘制对象,其用途不受限制。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多