Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
138 views
in Technique[技术] by (71.8m points)

How to Change image color dynamically in android?

I am doing such type of project ,In my project change Image color dynamically.

I have a one black shape color image ,when user click on this image change image color dynamically green.

enter image description here

Googling and other document follow but I am not solve my problem .

Please help me , is there any method or document to follow solve my problem ,

question from:https://stackoverflow.com/questions/14208367/how-to-change-image-color-dynamically-in-android

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here's how I do this: It's pulling the color from a resource xml file.

<resources>
<color name="new_color">#FFAAAAAA</color>
</resources>

In your activity .java file:

import android.graphics.PorterDuff.Mode;

Resources res = context.getResources();
final ImageView image = (ImageView) findViewById(R.id.imageId);
final int newColor = res.getColor(R.color.new_color);
image.setColorFilter(newColor, Mode.SRC_ATOP);

To clear it call:

image.setColorFilter(null);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...