【发布时间】:2015-01-26 07:12:42
【问题描述】:
在我构建的一个应用程序中,我注意到 ImageViews 在运行新的 Android Lollipop 的设备上没有着色。这是过去在旧版本操作系统上正常工作的代码:
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="bottom|right"
android:contentDescription="@string/descr_background_image"
android:src="@drawable/circle_shape_white_color"
android:tint="@color/intent_circle_green_grey" />
这是加载到 ImageView 中的可绘制对象:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
<gradient android:startColor="@color/white" android:endColor="@color/white"
android:angle="270"/>
</shape>
再一次,这在运行 JellyBean/Kitkat 的设备上正常工作,但色调对运行 Lollipop 的设备没有影响。任何想法如何解决它?这是操作系统中的错误,还是我应该开始对图像进行不同的着色?
【问题讨论】:
-
操作系统错误已在未来版本中修复。 ImageView 的 tint 属性已更新为使用 Drawable.setTint() 而不是 Drawable.setColorFilter(),但 GradientDrawable 不支持 setTint()。 XML 并没有很好的解决方法,但您可以从代码中调用 setColorFilter()。
-
太棒了,很高兴知道您已经处理好了!谢谢你的回答:)
标签: android imageview android-imageview android-5.0-lollipop