Why does Android Studio create the ic_launcher_foreground in res/drawable-v24 and the ic_launcher_background.xml in res/drawable?
Asked Answered
K

2

8

Firstly

I noticed when creating a new project in Android Studio it generates drawable-v24 folder with ic_launcher_foreground.xml icon.

And my question is:

  1. If vector drawables were introduced before v24 then why does it put the vector asset in drawable-v24 and not in drawable-v21 folder?

Secondly

Another generated asset is ic_launcher_background.xml which is created in res/drawable folder and was later referenced from mipmap-anydpi-v26/ic_launcher.xml.

  1. If it is only used in API v26+ (adaptive icons) then why was it created in res/drawable folder and not in res/drawable-v24 or in res/drawable-v26? Is it due to some nature of mipmap folders?
Kandi answered 2/8, 2019 at 12:50 Comment(1)
Did you find this answer ever?Brumal
W
2

The VectorDrawable feature is somewhat integrated in API-24 though it was introduced from API-21. I think Google's developers think API-24+ is ideal or stable for adaptive icons.

For example, Nick Butcher (Android designer + developer @ Google) said in his article: Using vector assets in Android apps (Dec 11, 2018),

  • Both nonZero and evenOdd path fillTypes —the two common ways of defining the inside of a shape, often used in SVGs (evenOdd added to platform impl in API 24)
  • Gradient & ColorStateList fills/strokes (added to platform impl in API 24)

And about ic_launcher_background, it is referenced only from mipmap-anydpi-v26/ic_launcher.xml and mipmap-anydpi-v26/ic_launcher_round.xml. I think it is just that there is no need to prevent from referencing it directly (It has already prevented by placing ic_launcher.xml and ic_launcher_round.xml in mipmap-anydpi-v26 folder). There should be not so far more, deep meanings.

Whoso answered 15/5, 2020 at 8:4 Comment(0)
S
2

A codelab answers your questions.

Depending on the min SDK of your app, you may notice that the foreground asset is located in the drawable-v24 folder, while the background asset is in the drawable folder. The reason is because the foreground asset contains a gradient, which was available starting in the Android 7.0 release (also known as API version 24, hence the -v24 resource qualifier). The background asset doesn't contain a gradient, so that can go in the base drawable folder.

As a side note, though we generally don't use ic_launcher_background.xml for any purpose other than the app icon, it is just a vector drawable and its usage is not limited.

Statesmanship answered 1/3, 2021 at 14:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.