需要更改图标的颜色。色调不起作用
Need to change the color of an icon. tint does not work
这是我的图片视图:
<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?
改为:
<?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>
这是我的图片视图:
<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?
改为:
<?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>