【发布时间】:2021-11-01 17:13:33
【问题描述】:
我在网上找不到任何关于此的内容,没有文档,什么都没有。也许你们中的一个人知道该怎么做,或者对我有一些建议。 提前谢谢你。
【问题讨论】:
我在网上找不到任何关于此的内容,没有文档,什么都没有。也许你们中的一个人知道该怎么做,或者对我有一些建议。 提前谢谢你。
【问题讨论】:
2022 年 2 月 18 日更新:Android 13 正式支持主题图标。只需在此处按照他们的步骤操作:https://developer.android.com/about/versions/13/features#themed-app-icons
以他们为榜样:
为您的应用图标创建单色版本
将此添加到您的ic_launcher.xml 文件中,在<adaptive-icon /> 标签集下:
<adaptive-icon>
<background android:drawable="..." />
<foreground android:drawable="..." />
<monochrome android:drawable="@drawable/myicon" />
</adaptive-icon>
将您的图标添加到清单中:
<application
…
android:icon="@mipmap/ic_launcher"
…>
</application>
注意:如果android:roundIcon 和android:icon 都在您的清单中,您必须删除对android:roundIcon 的引用或在android:roundIcon 定义的drawable 中提供单色图标属性。
所有这些都是直接从 Google 开发人员的示例中提取的。
对此似乎有相互竞争的答案,但 Material Components GitHub 存储库上的这个问题似乎提供了最深刻的见解:https://github.com/material-components/material-components-android/issues/2357
特别是使用自适应图标,像这样:
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt">
<background android:drawable="@color/launcher_icon_background"/>
<foreground>
<aapt:attr name="android:drawable">
<vector
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="@color/launcher_icon"
android:pathData="m54,74.5l23.3,-29c-0.9,-0.7 -9.9,-8 -23.3,-8c-13.4,0 -22.4,7.3 -23.3,8l23.3,29l0,0c0,0 0,0 0,0zm7.7,-27.3c1.4,1.7 2.3,3.9 2.3,6.3l0,2l-20,0l0,-2c0,-2.4 0.9,-4.6 2.3,-6.3l-2.3,-2.3l1.4,-1.4l2.3,2.3c1.7,-1.4 3.9,-2.3 6.3,-2.3c2.4,0 4.6,0.9 6.3,2.3l2.3,-2.3l1.4,1.4l-2.3,2.3zm-9.7,4.3c0,1.1 -0.9,2 -2,2c-1.1,0 -2,-0.9 -2,-2c0,-1.1 0.9,-2 2,-2c1.1,0 2,0.9 2,2zm8,0c0,1.1 -0.9,2 -2,2c-1.1,0 -2,-0.9 -2,-2c0,-1.1 0.9,-2 2,-2c1.1,0 2,0.9 2,2z" />
</vector>
</aapt:attr>
</foreground>
</adaptive-icon>
... 使用在 colors.xml 中定义的颜色,这些颜色是指派生自 Material 3 调色板的系统定义颜色:
<resources>
<color name="launcher_icon_background">@android:color/system_accent1_100</color>
<color name="launcher_icon">@android:color/system_neutral1_800</color>
</resources>
请注意,这些颜色源自系统定义的托盘,如 Material Design 3 中所述:https://m3.material.io/libraries/mdc-android/color-theming
您可能必须创建专门针对 API 31+ 的单独资源文件。我没有测试过这些建议。
【讨论】: