【问题标题】:Changing "fill color" of vector resource doesn't work更改矢量资源的“填充颜色”不起作用
【发布时间】:2017-08-15 00:58:54
【问题描述】:

我通过Android studioVector Asset创建了一个矢量资源资产,图标显示正确没有问题。 但是当我更改fill color 属性时,根本没有任何变化,并且图标保持其默认选中和未选中的颜色。 这是我的矢量 xml:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportHeight="51.0"
    android:viewportWidth="61.0">
    <path
        android:fillColor="@color/unselected"
        android:pathData="M59.28,1.7a5.67,5.67 0,0 0,-4.14 -1.71L5.86,-0.01a5.67,5.67 0,0 0,-4.14 1.71A5.54,5.54 0,0 0,0 5.79v39.42a5.54,5.54 0,0 0,1.72 4.09,5.67 5.67,0 0,0 4.14,1.71L55.14,51.01a5.67,5.67 0,0 0,4.14 -1.71A5.54,5.54 0,0 0,61 45.21v-39.42A5.54,5.54 0,0 0,59.28 1.7ZM18.77,45.21a1.12,1.12 0,0 1,-0.33 0.83,1.14 1.14,0 0,1 -0.84,0.33L5.86,46.37a1.14,1.14 0,0 1,-0.84 -0.33,1.12 1.12,0 0,1 -0.33,-0.83v-6.96a1.12,1.12 0,0 1,0.33 -0.83,1.14 1.14,0 0,1 0.84,-0.33L17.6,37.09a1.14,1.14 0,0 1,0.84 0.33,1.12 1.12,0 0,1 0.33,0.83v6.96ZM18.77,31.3a1.13,1.13 0,0 1,-1.17 1.16L5.86,32.46a1.14,1.14 0,0 1,-0.84 -0.33,1.13 1.13,0 0,1 -0.33,-0.83v-6.96a1.1,1.1 0,0 1,0.33 -0.83,1.14 1.14,0 0,1 0.84,-0.33L17.6,23.18a1.14,1.14 0,0 1,0.84 0.33,1.1 1.1,0 0,1 0.33,0.83v6.96ZM18.77,17.38a1.14,1.14 0,0 1,-0.33 0.84,1.17 1.17,0 0,1 -0.84,0.32L5.86,18.54a1.18,1.18 0,0 1,-0.84 -0.32,1.14 1.14,0 0,1 -0.33,-0.84v-6.95a1.14,1.14 0,0 1,0.33 -0.84,1.18 1.18,0 0,1 0.84,-0.32L17.6,9.27a1.17,1.17 0,0 1,0.84 0.32,1.14 1.14,0 0,1 0.33,0.84v6.95ZM37.54,45.21a1.12,1.12 0,0 1,-0.33 0.83,1.14 1.14,0 0,1 -0.84,0.33L24.63,46.37a1.14,1.14 0,0 1,-0.84 -0.33,1.12 1.12,0 0,1 -0.33,-0.83v-6.96a1.12,1.12 0,0 1,0.33 -0.83,1.14 1.14,0 0,1 0.84,-0.33L36.37,37.09a1.14,1.14 0,0 1,0.84 0.33,1.12 1.12,0 0,1 0.33,0.83v6.96h0ZM37.54,31.3a1.13,1.13 0,0 1,-1.17 1.16L24.63,32.46a1.14,1.14 0,0 1,-0.84 -0.33,1.13 1.13,0 0,1 -0.33,-0.83v-6.96a1.1,1.1 0,0 1,0.33 -0.83,1.14 1.14,0 0,1 0.84,-0.33L36.37,23.18a1.14,1.14 0,0 1,0.84 0.33,1.1 1.1,0 0,1 0.33,0.83v6.96h0ZM37.54,17.38a1.14,1.14 0,0 1,-0.33 0.84,1.17 1.17,0 0,1 -0.84,0.32L24.63,18.54a1.18,1.18 0,0 1,-0.84 -0.32,1.14 1.14,0 0,1 -0.33,-0.84v-6.95a1.14,1.14 0,0 1,0.33 -0.84,1.18 1.18,0 0,1 0.84,-0.32L36.37,9.27a1.17,1.17 0,0 1,0.84 0.32,1.14 1.14,0 0,1 0.33,0.84v6.95h0ZM56.31,45.21a1.12,1.12 0,0 1,-0.33 0.83,1.14 1.14,0 0,1 -0.84,0.33L43.4,46.37a1.14,1.14 0,0 1,-0.84 -0.33,1.12 1.12,0 0,1 -0.33,-0.83v-6.96a1.12,1.12 0,0 1,0.33 -0.83,1.14 1.14,0 0,1 0.84,-0.33L55.14,37.09a1.14,1.14 0,0 1,0.84 0.33,1.12 1.12,0 0,1 0.33,0.83v6.96ZM56.31,31.3a1.13,1.13 0,0 1,-0.33 0.83,1.14 1.14,0 0,1 -0.84,0.33L43.4,32.46a1.13,1.13 0,0 1,-1.17 -1.16v-6.96a1.1,1.1 0,0 1,0.33 -0.83,1.14 1.14,0 0,1 0.84,-0.33L55.14,23.18a1.14,1.14 0,0 1,0.84 0.33,1.1 1.1,0 0,1 0.33,0.83v6.96ZM56.31,17.38a1.14,1.14 0,0 1,-0.33 0.84,1.18 1.18,0 0,1 -0.84,0.32L43.4,18.54a1.17,1.17 0,0 1,-0.84 -0.32,1.14 1.14,0 0,1 -0.33,-0.84v-6.95a1.14,1.14 0,0 1,0.33 -0.84,1.17 1.17,0 0,1 0.84,-0.32L55.14,9.27a1.18,1.18 0,0 1,0.84 0.32,1.14 1.14,0 0,1 0.33,0.84v6.95Z" />
</vector>

@color/unselected 不起作用,图标保持默认#FF000000

我在 BottomNavigation Layout 中使用这些向量,它会扩展导航菜单 xml 文件,如下所示:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
    android:id="@+id/navigation_time"
    android:icon="@drawable/ic_time"
    android:tint="@color/unselected"
    android:title="@string/title_time"
    app:showAsAction="always|withText" />

<item
    android:id="@+id/navigation_late"
    android:icon="@drawable/ic_late"
    android:tint="@color/unselected"
    android:title="@string/title_late"
    app:showAsAction="always|withText" />

<item
    android:id="@+id/navigation_file"
    android:icon="@drawable/ic_file"
    android:tint="@color/unselected"
    android:title="@string/title_file"
    app:showAsAction="always|withText" />

<item
    android:id="@+id/navigation_attach"
    android:icon="@drawable/ic_attach"
    android:tint="@color/colorPrimaryDark"
    android:title="@string/title_attach"
    app:showAsAction="always|withText" />

<item
    android:id="@+id/navigation_table"
    android:icon="@drawable/ic_table"
    android:tint="@color/colorPrimaryDark"
    android:title="@string/title_table"
    app:showAsAction="always|withText" />

我尝试了 tint 属性,但没有任何改变...

【问题讨论】:

标签: android


【解决方案1】:

尝试在布局 XML 的“底部 NavigationView”定义中设置“app:itemIconTint="@color/yourColor"' 属性。就我而言,我在 NavigationView 上遇到了类似的问题。这就是我修复它的方法:

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    app:itemIconTint="@color/scrollbarColor" />

希望对您有所帮助。

【讨论】:

    【解决方案2】:

    我删除了元素附带的以下属性:

    android:tint="?attr/colorControlNormal"
    

    之后,元素的以下属性开始正常工作。

    android:fillColor="#830E0E"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-31
      • 2018-01-26
      • 1970-01-01
      • 1970-01-01
      • 2021-11-24
      • 1970-01-01
      • 1970-01-01
      • 2020-05-12
      相关资源
      最近更新 更多