Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Android how can I make ImageView darker onClick

As an iOS developer told me, iOS make an image darker when somebody tap it (I don't know how true it is) so I need the same thing.

as I understand, I need a usual selector.xml to make a drawable with different states. What I need is to darken the image in a simple way, may be in xml-drawable somehow so I don't have to use Photoshop in which I have no skill.

Is there a way to do so on xml-level?

like image 366
Vlad Alexeev Avatar asked Nov 28 '13 12:11

Vlad Alexeev


1 Answers

You could use the following code in your java class:

mView.getBackground().setColorFilter(Color.parseColor(<Color code of your choice>), PorterDuff.Mode.DARKEN);

This line above changes the color of the view to to a share of color you suggest in Color.parseColor() and a shade like how you define it using PorterDuff.Mode. Call the above code on click of a button to check if the color change is taking effect.

like image 134
stack_ved Avatar answered Sep 21 '22 03:09

stack_ved