安卓实现一图多色-ImageView的tint属性

效果图

安卓实现一图多色-ImageView的tint属性

方案介绍

在安卓中常常会遇到同一张图片,而颜色不同的场景.那怎么办呢?

  • 常见的做法: 多做几张图
    这事有几大缺点:
    设计师烦,明明是创造性的活动,变成了体力活.
    app烦,无形中app变大了许多.
  • 更优解
    一张图,采用ImageView的tint属性实现多种颜色的图片.

使用样例

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/milk_tea"
    android:tint="#f58f98" />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/milk_tea"
    android:tint="#faa755" />

PS: 除了tint属性,也可以通过setColorFilter来改变颜色

imageView.setColorFilter(Color.parseColor("#00FF00"))

完整源代码

https://gitee.com/cxyzy1/tint-demo

© 版权声明
THE END
如果内容对您有所帮助,就支持一下吧!
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容