我需要找到一种在Android中改变位图颜色的方法。我需要在我的应用程序中平滑地替换/更改椭圆形图像的颜色,这取决于int
值。我需要像这样的东西:如果myValue=5
,则将我的图像颜色更改为RED
,如果myValue=322
,则将颜色更改为BLUE
。我发现唯一能做到这一点的方法是使用XML文件,它看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" android:padding="10dp">
<!-- you can use any color you want I used here gray color-->
<solid android:color="#cccccc"/>
<corners
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp"/>
</shape>
当
myValue
发生变化时,我希望设置我的ImageView
图像资源。但是这样我需要创建35个不同的XML文件...我认为这不是一个好主意。有没有人能提供更好的解决方案?
imageview
的android:tint
属性中使用。 - Bhargav