【发布时间】:2012-05-14 01:29:45
【问题描述】:
我需要找到一种方法来更改 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 文件……我认为这不是一个好主意。
那么任何人都可以提出更好的解决方案吗?
【问题讨论】:
标签: android bitmap android-imageview