图标变浅,看起来像变灰了

时间:2019-04-13 04:38:29

标签: android android-vectordrawable

我有一个奇怪的错误。

我将图像作为矢量资产。它创建正确,如下所示:

enter image description here

我正在像抽屉上的菜单图标一样使用它:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <group android:checkableBehavior="single">
        <item
            android:id="@+id/about"
            android:icon="@drawable/ic_about_us"
            android:title="@string/navigation_about" />
    </group>
</menu>

但是在设备中,它看起来很破损:

enter image description here

您是否在背景上看到图像?它也是矢量资产,但它们可以正常工作。我将其放置在代码中。

我对ViewPager图标有类似的问题。似乎只有图标坏了。所以我有两个向量资产:

enter image description here

enter image description here

我以两种不同的方式(特别地)设置了这些图标:

layout_tab.getTabAt(0)?.icon = activity?.getDrawable(R.drawable.ic_type_bird)
layout_tab.getTabAt(1)?.setIcon(R.drawable.ic_hints)

然后我看到:

一个:

enter image description here

两个:

enter image description here

这是怎么回事,为什么我的资产坏了?

1 个答案:

答案 0 :(得分:1)

您的资产没有损坏,只是导航抽屉自动将滤色器应用于图标,使它们显示为灰色。标签栏与它类似(因为它试图显示状态)

answer here显示了如何停止此操作