android - How do I set a color filter on a drawable which will be used in a RemoteView? -


i have imaveview on remoteview have apply filter. when not in remoteview , works well:

    drawable icon = getresources().getdrawable(r.drawable.icon);     icon.setcolorfilter(color, porterduff.mode.src_in);     image.setimagedrawable(icon); 

the remoteview not appear have method me set drawable not resource. how go doing this?

thanks.

i had similar problem. me solution use bitmap. these 2 methods should give answer or @ least kind of solution.

private void setcurrentstatus(context context, remoteviews remoteviews) {     bitmap source = bitmapfactory.decoderesource(context.getresources(), r.mipmap.ic_launcher);     bitmap result = changebitmapcolor(source, color.yellow);      remoteviews.setbitmap(r.id.iv_icon, "setimagebitmap", result); }  private bitmap changebitmapcolor(bitmap sourcebitmap, int color) {     bitmap resultbitmap = bitmap.createbitmap(sourcebitmap, 0, 0,             sourcebitmap.getwidth() - 1, sourcebitmap.getheight() - 1);     paint p = new paint();     colorfilter filter = new porterduffcolorfilter(color, porterduff.mode.src_in);     p.setcolorfilter(filter);      canvas canvas = new canvas(resultbitmap);     canvas.drawbitmap(resultbitmap, 0, 0, p);      return resultbitmap; } 

r.id.iv_icon - id of imageview layout

you can drawable imageview , convert bitmap.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -