Last active
December 17, 2016 07:55
-
-
Save Eklett/4c60fe233da6e2f3c855c2c2c0978457 to your computer and use it in GitHub Desktop.
与drawable相关的一些操作
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.graphics.drawable.Drawable; | |
import android.graphics.PorterDuff; | |
import android.support.annotation.ColorInt; | |
import android.support.v4.graphics.drawable.DrawableCompat; | |
import android.widget.ImageView; | |
public class DrawableUtils { | |
/** | |
* 以SRC_ATOP的方式改变imageview图片的颜色 | |
*/ | |
public static void changeImageDrawable(ImageView imageView, @ColorInt int color) { | |
Drawable drawable = imageView.getDrawable(); | |
drawable = DrawableCompat.wrap(drawable); | |
DrawableCompat.setTint(drawable, color); | |
DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_ATOP); | |
imageView.setImageDrawable(drawable); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment