i use this library to show svg image on imageView , i want to show locked and unlocked mode with this imageView, when state is locked show imageView in grayscale color filter. something like this code on css :
-webkit-filter: grayscale(100%); opacity: 0.5;
how can i do this ? can anybody help me ? thanks
To set all the views to grayscale, for TextView we have to use setTextColor to set a new color. For ImageView we can set a new resource which in itself is grayscale or use setColorFilter .
Right-click the picture that you want to change, and then click Format Picture on the shortcut menu. Click the Picture tab. Under Image control, in the Color list, click Grayscale or Black and White.
You should be able to make the image greyscale and faded using the following:
public static void setLocked(ImageView v) { ColorMatrix matrix = new ColorMatrix(); matrix.setSaturation(0); //0 means grayscale ColorMatrixColorFilter cf = new ColorMatrixColorFilter(matrix); v.setColorFilter(cf); v.setImageAlpha(128); // 128 = 0.5 }
And reset it using:
public static void setUnlocked(ImageView v) { v.setColorFilter(null); v.setImageAlpha(255); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With