android app widget dynamic background color with rounded corners android 2.3 -


i'm facing problem implementation of changing widget background color dynamically in android 2.3.

i used approach implementation: http://oceanuz.wordpress.com/2013/07/11/widget-remoteviews-round-corners-background-and-colors/

so have imageview in widgetlayout:

 <imageview      android:id="@+id/widget_background_image"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:src="@drawable/widget_bg_shape" /> 

this how widget_bg_shape looks like:

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"     android:shape="rectangle" >     <solid         android:color="#496fb3"/>     <corners         android:radius="3dp" /> </shape> 

and code changing background color based on user preferences:

private static void setbackgroundcolor(context pcontext, int pwidgetid,         remoteviews remoteviews) {     float[] color = { 218, 59 / 100f, 70 / 100f };     int transparency = 192;     sharedpreferences settings = pcontext.getsharedpreferences("widget"             + pwidgetid, context.mode_private);     color.colortohsv(settings.getint("color", color.hsvtocolor(color)),             color);     transparency = settings.getint("transparency", transparency);     remoteviews.setint(r.id.widget_background_image, "setcolorfilter",             color.hsvtocolor(color));      if (build.version.sdk_int >= build.version_codes.jelly_bean) {         remoteviews.setint(r.id.widget_background_image, "setimagealpha",                 transparency);     } else {         remoteviews.setint(r.id.widget_background_image, "setalpha",                 transparency);     } 

so on newer android versions works fine, on android 2.3 (testing on samsung s+ android 2.3.6, had user feedback other devices) background transparent.

i found out, either setcolorfilter or setalpha call on remoteview caused image transparent or not there.

according article postet above , stackoverflow question referenced (rounded corners on dynamicly set imageview in widget?) should work on android 2.2 , obove. in case not.

can me this?

better late never:

i fixed issue removing default color background drawable shape android 2.x

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"     android:shape="rectangle" >     <corners android:radius="3dp" /> </shape> 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -