更改矢量应用程序图标的背景颜色

我正在尝试在 android 上创建一个小助手以获得乐趣,我想使用与谷歌助手相同的图标,但背景为深色,但它不起作用:

http://img4.mukewang.com/61b315030001342101490091.jpg

我尝试使用具有形状(圆形或一个正方形),但它并不完全适合圆形图标。我也试过:


<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@color/midnightblue"/>

    <item android:drawable="@drawable/ic_assistant"/>

</layer-list>

但正如您在屏幕截图上看到的,我得到了相同的结果。你有什么主意吗?


素胚勾勒不出你
浏览 310回答 1
1回答

眼眸繁星

尝试将启动器图标背景设置为白色。例如在res/mipmap-anydpi-v26目录中:ic_launcher.xml<?xml version="1.0" encoding="utf-8"?><adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">&nbsp; &nbsp; <background android:drawable="@drawable/ic_launcher_background" />&nbsp; &nbsp; <foreground android:drawable="@drawable/ic_launcher" /></adaptive-icon>ic_launcher_round.xml<?xml version="1.0" encoding="utf-8"?><adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">&nbsp; &nbsp; <background android:drawable="@drawable/ic_launcher_background" />&nbsp; &nbsp; <foreground android:drawable="@drawable/ic_launcher_round" /></adaptive-icon>并在res/drawable目录中:ic_launcher_background.xml<?xml version="1.0" encoding="utf-8"?><vector xmlns:android="http://schemas.android.com/apk/res/android"&nbsp; &nbsp; android:width="108dp"&nbsp; &nbsp; android:height="108dp"&nbsp; &nbsp; android:viewportHeight="108"&nbsp; &nbsp; android:viewportWidth="108">&nbsp; &nbsp; <path&nbsp; &nbsp; &nbsp; &nbsp; android:fillColor="#FFFFFF"&nbsp; &nbsp; &nbsp; &nbsp; android:pathData="M0,0h108v108h-108z" /></vector>毕竟,我们可以缩放内部图标以强制将其包含在圆圈中。ic_assistant.xml<?xml version="1.0" encoding="utf-8"?><vector xmlns:android="http://schemas.android.com/apk/res/android"&nbsp; &nbsp; android:width="48dp"&nbsp; &nbsp; android:height="48dp"&nbsp; &nbsp; android:viewportWidth="512"&nbsp; &nbsp; android:viewportHeight="512">&nbsp; &nbsp; <group&nbsp; &nbsp; &nbsp; &nbsp; android:scaleX="0.5"&nbsp; &nbsp; &nbsp; &nbsp; android:scaleY="0.5"&nbsp; &nbsp; &nbsp; &nbsp; android:translateX="128"&nbsp; &nbsp; &nbsp; &nbsp; android:translateY="128">&nbsp; &nbsp; &nbsp; &nbsp; <path&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:fillColor="#4285F4"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:pathData="M156.268,167.705m-156.268,0a156.268,156.268 0,1 1,312.536 0a156.268,156.268 0,1 1,-312.536 0" />&nbsp; &nbsp; &nbsp; &nbsp; <path&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:fillColor="#34A853"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:pathData="M512,182.95c0,17.544 -14.224,31.762 -31.762,31.762s-31.762,-14.218 -31.762,-31.762c0,-17.543 14.224,-31.762 31.762,-31.762S512,165.407 512,182.95z" />&nbsp; &nbsp; &nbsp; &nbsp; <path&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:fillColor="#EA4335"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:pathData="M454.829,260.449c0,35.081 -28.438,63.522 -63.523,63.522c-35.088,0 -63.524,-28.441 -63.524,-63.522c0,-35.083 28.437,-63.524 63.524,-63.524C426.392,196.925 454.829,225.367 454.829,260.449z" />&nbsp; &nbsp; &nbsp; &nbsp; <path&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:fillColor="#FBBC05"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:pathData="M467.533,424.339c0,42.1 -34.124,76.225 -76.228,76.225c-42.104,0 -76.229,-34.125 -76.229,-76.225c0,-42.098 34.124,-76.227 76.229,-76.227C433.409,348.112 467.533,382.241 467.533,424.339z" />&nbsp; &nbsp; </group></vector>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java