【问题标题】:Use style/theme colour on a vector asset在矢量资产上使用样式/主题颜色
【发布时间】:2021-02-04 14:17:51
【问题描述】:

您好,我正在尝试设置填充颜色以使用 colorOnPrimary 的主题/样式

通过 android:fillColor="?colorOnPrimary"

但是我得到这个错误:Invalid color value ?colorOnPrimary 当我尝试构建我的项目时

这就是我的矢量资产 xml 的样子:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="18dp"
    android:height="18dp"
    android:viewportWidth="18"
    android:viewportHeight="18">
    <path
        android:fillColor="?colorOnPrimary"
        android:fillType="evenOdd"
        android:pathData="...." />
</vector>

【问题讨论】:

    标签: android material-design android-vectordrawable android-attributes


    【解决方案1】:

    对于color 使用颜色资源和@color,您可能在colors.xml 中有colorPrimary

    <vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="18dp"
        android:height="18dp"
        android:viewportWidth="18"
        android:viewportHeight="18">
        <path
            android:fillColor="@color/colorOnPrimary"
            android:fillType="evenOdd"
            android:pathData="...." />
    </vector>
    

    【讨论】:

    • 没有 colorPrimary 而是一个 design_default_color_on_primary
    猜你喜欢
    • 2020-01-29
    • 2015-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-20
    • 1970-01-01
    • 2021-03-30
    相关资源
    最近更新 更多