How to color gray ressource icons in android (especially microphone)
i'm currently developing an application for android. Therefore i want to create a microphone widget, like the one in googles Searchdialog. This icon is filled with white color, like a bargraph, depending on the recorded volume level. I already found the icon (ic_btn_speak_now.png) 开发者_JS百科in the drawable ressources, delivered with the SDK.
Unfortunately the icon isn't an simple shape with a transparent area for the microphone shape. Instead it consists of some different gray values. My question now is:
How do the google developers (and others, where i've seen it) fill only the microphone shape of the icon with color?
I hope that one of you has an idea!
One possibility could be to create an icon with a transparent microphone shape in the center and change the background color?
Try applying a color filter: http://developer.android.com/reference/android/graphics/ColorFilter.html
To be more precise:
By using a ColorMatrixColorFilter
, you can apply a ColorMatrix
to the icon. That way, you can increase the value of a particular color, thus tinting it. For example, to tint it red:
float[] f = new float[] {1, 0, 0, 1, 50, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0};
icon.setColorFilter(new ColorMatrixColorFilter(new ColorMatrix(f)));
But that's just off the top of my head. You'll probably have to play around with the matrix yourself.
精彩评论