需要更改图标的颜色。色调不起作用

时间:2018-10-09 15:31:14

标签: android colors imageview selector tint

这是我的图像视图:

  <ImageView
                android:id="@+id/action_add_iv"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_centerVertical="true"
                android:layout_marginRight="12dp"
                android:tint="@color/gray32"
                android:background="@drawable/plus_selector"
                android:text="0" />

这是我的选择器:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
    <bitmap android:alpha="160" android:src="@drawable/btn_plus_green" android:tint="@color/gray32" />
</item>
<item android:drawable="@drawable/btn_plus_green" android:state_pressed="false" android:tint="@color/gray32" />
</selector>

现在,如果我按图标,它会变成灰色,如我所愿。但是,如果未按,则显示为绿色。为什么色调也不适用于state_pressed = false?

1 个答案:

答案 0 :(得分:1)

将其更改为:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <bitmap android:alpha="160" android:src="@drawable/btn_plus_green" android:tint="@color/gray32" />
    </item>
    <item android:state_pressed="false">
        <bitmap android:src="@drawable/btn_plus_green" android:tint="@color/gray32" />
    </item>
</selector>