temp_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="@color/color1" />
<item android:state_selected="true" android:color="@color/color2" />
<item android:color="@color/color3" />
</selector>
我通过下面的代码应用了它
imageView.setImageResource(R.drawable.image)
ImageViewCompat.setImageTintList(imageView, ColorStateList.valueOf(R.color.temp_selector))
我不知道为什么它不起作用。。。我该怎么办?(它必须以程序方式应用。而不是xml。(
使用下面的更改颜色
imageView.isSelected = true
imageView.isSelected = false
使用以下选择器:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/color3" android:state_selected="false" />
<item android:color="@color/color2" android:state_selected="true"/>
<item android:color="@color/color1" android:state_pressed="true" />
</selector>