首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用Android中的值替换< android:drawable="@color/ic_meter_launcher_background"/>背景值?

如何用Android中的值替换< android:drawable="@color/ic_meter_launcher_background"/>背景值?
EN

Stack Overflow用户
提问于 2022-09-04 11:42:47
回答 2查看 136关注 0票数 3

代码A由Android自动生成。

我希望用颜色值代替<background android:drawable="@color/ic_meter_launcher_background"/>,但是代码B和代码C都错了。

我该怎么做?

码A

ic_meter_launcher_background.xml文件

ic_launcher.xml文件

码B

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@color/#3DDC84"/>
    <foreground android:drawable="@drawable/ic_meter_launcher_foreground"/>
</adaptive-icon>

代码C

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="#3DDC84"/>
    <foreground android:drawable="@drawable/ic_meter_launcher_foreground"/>
</adaptive-icon>
EN

回答 2

Stack Overflow用户

发布于 2022-09-08 10:01:48

您可以覆盖Android应用程序的任何资源,甚至框架本身:

<color tools:override="true" name="ic_meter_launcher_background">#3DDC84</color>

在您的资源XML文件头中,tools应该是xmlns:tools="http://schemas.android.com/tools"

票数 0
EN

Stack Overflow用户

发布于 2022-09-12 10:07:08

你可以这样做:

ic_launcher.xml文件

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@drawable/ic_meter_launcher_background"/>
    <foreground android:drawable="@drawable/ic_meter_launcher_foreground"/>
</adaptive-icon>

ic_meter_launcher_background.xml

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="108dp"
    android:height="108dp"
    android:viewportWidth="108"
    android:viewportHeight="108">
    <path
        android:fillColor="#3F3F4A"
        android:pathData="M0,0h108v108h-108z" />
</vector>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73599079

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档