Android: Tint using DrawableCompat

In case anyone needs to use DrawableCompat‘s tinting without affecting other drawables, here’s how you do it with mutate(): Drawable drawable = getResources().getDrawable(R.drawable.some_drawable); Drawable wrappedDrawable = DrawableCompat.wrap(drawable); wrappedDrawable = wrappedDrawable.mutate(); DrawableCompat.setTint(wrappedDrawable, getResources().getColor(R.color.white)); Which can be simplified to: Drawable drawable = getResources().getDrawable(R.drawable.some_drawable); drawable = DrawableCompat.wrap(drawable); DrawableCompat.setTint(drawable.mutate(), getResources().getColor(R.color.white));

jQuery: there is a way to apply colour (tint) to an image?

Simplest way I can think of is overlaying a semitransparent div over the image. A little example: HTML <div id=”overlay” class=”overlay”></div> <img id=”myimg” src=”https://stackoverflow.com/questions/4416007/img.jpg” /> CSS .overlay { display: block; position: absolute; background-color: rgba(200, 100, 100, 0.5); top: 0px; left: 0px; width: 0px; height: 0px; } JS (with JQuery) overlay = $(“#overlay”); img = $(“#myimg”); … Read more

MenuItem tinting on AppCompat Toolbar

After the new Support library v22.1, you can use something similar to this: @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_home, menu); Drawable drawable = menu.findItem(R.id.action_clear).getIcon(); drawable = DrawableCompat.wrap(drawable); DrawableCompat.setTint(drawable, ContextCompat.getColor(this,R.color.textColorPrimary)); menu.findItem(R.id.action_clear).setIcon(drawable); return true; }

How would I tint an image programmatically on iOS?

In iOS7, they’ve introduced tintColor property on UIImageView and renderingMode on UIImage. To tint an UIImage on iOS7, all you have to do is: UIImageView* imageView = … UIImage* originalImage = … UIImage* imageForRendering = [originalImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; imageView.image = imageForRendering; imageView.tintColor = [UIColor redColor]; // or any color you want to tint it with

How to set tint for an image view programmatically in android?

UPDATE: @ADev has newer solution in his answer here, but his solution requires newer support library – 25.4.0 or above. You can change the tint, quite easily in code via: imageView.setColorFilter(Color.argb(255, 255, 255, 255)); // White Tint If you want color tint then imageView.setColorFilter(ContextCompat.getColor(context, R.color.COLOR_YOUR_COLOR), android.graphics.PorterDuff.Mode.MULTIPLY); For Vector Drawable imageView.setColorFilter(ContextCompat.getColor(context, R.color.COLOR_YOUR_COLOR), android.graphics.PorterDuff.Mode.SRC_IN);

Lollipop’s backgroundTint has no effect on a Button

The bad news Like BoD says, it’s meaningless to tint a Button’s background in Lollipop 5.0 (API level 21). The good news Lollipop 5.1 (API level 22) seems to have fixed this by changing btn_mtrl_default_shape.xml (among other files): https://android.googlesource.com/platform/frameworks/base/+/6dfa60f33ca6018959ebff1efde82db7d2aed1e3%5E!/#F0 The great news The new support library (version 22.1+) adds backward-compatible tinting support to lots of … Read more