我已经在图像资源工具中创建了所有的自适应图标,但没有创建ic_launcher_foreground.xml文件-这反过来会导致我的构建失败,因为ic_launcher.xml和ic_launcher_round.xml文件中引用了foreground.xml文件。
我读了很多关于如何解决这个问题的帖子,但没有一个是有效的。
同样,ic_launcher.xml和ic_launcher_round.xml文件都特别引用了这两个文件:
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@mipmap/ic_launcher_foreground" />正在使用ic_launcher_background.xml文件创建/drawable文件夹,但图像资源工具并未创建/mipmap文件夹-它看起来正在创建所有其他/mipmap-XYZdpi文件夹和图标。
我之所以提到这一点,是因为许多其他线程都显示ic_launcher.xml和ic_launcher_round.xml文件同时引用了同一个/drawable文件夹中的background.xml和foreground.xml文件,这与我上面的不同。
在图像资源:前景选项卡中:层名称:资源资源类型:图像路径:/dev/myApp/ ic_launcher_foreground /myCustomIcon.png背景选项卡:层名称: ic_launcher_background资源类型:图像路径: res/drawable/ic_launcher_ Background .xml
只有在前景选项卡上选择了Asset Type: Clip Art时,我才能让ic_launcher_foreground.xml文件出现在“输出文件”屏幕上
更新:
我将该文件复制到我的项目res/drawable文件夹中-现在,当我的应用程序编译到我的测试设备上时,我会获得Android half机器人图标。
发布于 2020-04-22 20:40:37
好吧,我终于想明白了。将我的答案发布给其他有同样问题的人。
使用图像资源工具-只有当每种类型(前景选项卡/背景选项卡)资源类型被定义为任何类型而不是图像类型时,才会生成ic_launcher_foreground.xml和ic_launcher_background.xml。PNG/JPG资源类型不会生成这些xml文件。
无论资产类型如何,都将生成ic_launcher.xml和ic_launcher_round.xml。如果资源类型为color/art/text,则这两个xml文件仅引用其他文件-引用将位于@drawable/文件夹或@values/文件夹中的其他XML文件。
<background android:drawable="@drawable/ic_launcher_background" /> OR
<background android:drawable="@values/ic_launcher_background" />
//@drawable - is the root of all your drawables folders
// - and references only XML, ie: ie_launcher_background.xml如果资产类型是图像( png/jpg ),则引用将指向存在于任何@mipmap文件夹中的新创建的png/jpg文件。
<foreground android:drawable="@mipmap/ic_launcher_foreground" />
// @mipmap is simply root of all your mipmap folders
// references actual png files, ie: ic_launcher_foreground.png最后,如果您使用的是Cordova,则需要修改您的config.xml以反映要使用的图标文件:
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
<application android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" />
</edit-config>
// this telling the app to find those two XML files in the mipmap-anydpi-v26 folder
// and those files in turn tell the app to find all the png files in the other "mipmap" folders
// if it were this:
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
<application android:icon="@drawable/ic_launcher" android:roundIcon="@drawable/ic_launcher_round" />
</edit-config>
// this telling the app to use the XML files sourced in the drawable folders
// if you used png as foreground and color as background
// ic_launcher.xml/ic_launcher_round.xml would both point to:
// @mipmap/ic_launcher_foreground (ie: png images)
// @drawable/ic_launcher_background (ie: xml files)我希望这对其他人有所帮助,因为我觉得上面的所有内容在其他文档中都没有得到很好的解释。
发布于 2020-11-20 03:58:23
现在很简单:右键单击"res“或"mipmap”文件夹启动"Image Asset Studio“,然后从弹出菜单中选择"New > Image Asset”。Image Asset Studio现在将打开。现在,您可以根据需要创建自适应启动器图标或仅传统启动器图标。
要更新和现有图标,只需选择现有的ic_launcher_foreground.xml文件和ic_launcher_background.xml文件,然后点击“下一步”创建新的定义,覆盖旧的定义。
发布于 2021-07-26 22:25:39
我的所作所为..。(经常发生的情况是,其他人说他们最终修复了它的解决方案对我永远不起作用,所以我想我应该贡献另一个可能只对我起作用的解决方案:)
首先,我按原样生成了图像资产文件。我右击res文件夹,单击“新建”,然后单击“图像资产”。我保留“源资产”路径不变(带有launcher_foreground.xml文件的路径)并创建资产。
然后,我返回并再次生成图像资源,但这一次是使用我自己的png图像。到目前为止似乎已经奏效了,至少在下一次更新使这个解决方案过时之前是这样。
https://stackoverflow.com/questions/61290753
复制相似问题