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
Post a Comment