android - Change color of background drawable of a button from widgetprovider -
in normal android code in activity, can control color of background drawable
drawable d = findviewbyid(r.id.button_highlight).getbackground(); porterduffcolorfilter filter = new porterduffcolorfilter(color.red, porterduff.mode.src_atop); d.setcolorfilter(filter);
i know how can utilize within widgetprovider dynamically change background color of background drawable of elements
from instance of appwidgetprovider call like:
int color2 = settings.getint("secondary_color", r.color.main_alt); // following won't work because <button> has no method "setcolorfilter" remoteviews.setint(r.id.button_highlight,"setcolorfilter",color2);
the button_bg.xml drawable button id r.id.highlight looks this:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"> <shape> <corners android:toprightradius="5dp" android:bottomrightradius="5dp"/> <solid android:color="@color/main_alt"/> <padding android:bottom="5dp" android:left="5dp" android:right="5dp" android:top="5dp"/> </shape> </item> <item> <shape> <corners android:toprightradius="5dp" android:bottomrightradius="5dp"/> <solid android:color="@color/main"/> <padding android:bottom="5dp" android:left="5dp" android:right="5dp" android:top="5dp"/> </shape> </item> </selector>
are there workarounds? missing something? how can change color of background drawable? thinking of subclassing button , implement custom methods set color first wanted know if there more common or easier ways..
setcolorfilter(int color, porterduff.mode mode) doesn't have @remotableviewmethod annotation can't used in remoteviews.
my best bet convert drawable bitmap , use remoteviews.setimagebitmap(): http://developer.android.com/reference/android/widget/remoteviews.html#setimageviewbitmap(int, android.graphics.bitmap) haven't tested it's worth trying. found methods don't work in remote views if have @remotableviewmethod annotation, might or might not work.
you'll find answers on how convert drawable bitmap here on so, e.g. here: https://stackoverflow.com/a/9390776/534471
Comments
Post a Comment