[英]Change color of an image in android
I wonder if there is a way to change the color of my image on the button easily, my simple example is like this, 我想知道是否有办法轻松改变按钮上图像的颜色,我的简单示例是这样的,
CircleButton.setImageResource(android.R.drawable.ic_media_play);
I have a play audio icon (white) and want to change the icon color to red, like this 我有一个播放音频图标(白色),想要将图标颜色更改为红色,就像这样
CircleButton.setImageResource(ColorChange(Red, android.R.drawable.ic_media_play));
What seems to be the easiest way for doing ColorChange() ? 什么似乎是做ColorChange()最简单的方法?
Use ColorFilter
to change the button
image color. 使用
ColorFilter
更改button
图像颜色。 Your button should be ImageButton
你的按钮应该是
ImageButton
Set the image resource to the ImageButton
将图像资源设置为
ImageButton
CircleButton.setImageResource(android.R.drawable.ic_media_play);
And, change the image color when required like this 并且,在需要时更改图像颜色
CircleButton.setColorFilter(getResources().getColor(R.color.any_color));
Refer : http://developer.android.com/reference/android/graphics/drawable/Drawable.html#setColorFilter(android.graphics.ColorFilter) 参考: http : //developer.android.com/reference/android/graphics/drawable/Drawable.html#setColorFilter(android.graphics.ColorFilter)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.