Tome este diseño widget de, por ejemplo, (parte de mi diseño widget de todo)Cómo cambiar el fondo de diseño widget de programáticamente
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/widget_background_dark_4x2"
android:orientation="horizontal"
android:id="@+id/widget_main"
>
Quiero ser capaz de cambiar el fondo estirable utilizado basado en una selección de usuarios. Por ejemplo el uso de vistas remotas puedo actualizar el color de un TextView haciendo algo como esto:
remoteView.setTextColor(R.id.text_view1, Color.WHITE);
Sin embargo, he estado encontrando dificultades para el mismo para el fondo de mi diseño lineal. Yo probé esto:
remoteView.setBitmap(R.id.widget_main, "setBackgroundDrawable", ((BitmapDrawable) context.getResources().getDrawable(R.drawable.widget_background_dark_4x2)).getBitmap());
Pero me sale el siguiente error:
06-01 22:46:36.305: WARN/AppWidgetHostView(244): android.widget.RemoteViews$ActionException: view: android.widget.LinearLayout doesn't have method: setBackgroundDrawable(android.graphics.Bitmap)
Cualquier ayuda con esto sería muy apreciada.
< < EDITAR >> también han intentado esto:
Bitmap bitmap = ((BitmapDrawable)context.getResources().getDrawable(R.drawable.widget_background_light_4x2)).getBitmap();
remoteView.setBitmap(R.id.widget_main, "setBackgroundDrawable",bitmap);
Pero, por desgracia el siguiente error:
06-01 23:11:26.039: WARN/AppWidgetHostView(244): updateAppWidget couldn't find any view, using error view 06-01 23:11:26.039: WARN/AppWidgetHostView(244): android.widget.RemoteViews$ActionException: view: android.widget.LinearLayout doesn't have method: setBackgroundDrawable(android.graphics.Bitmap)
es práctico .. Gracias por compartir :) – Fon