举个例子,这是一个小部件布局(我的整个小部件布局的一部分)。
但是我遇到了以下错误:
但不幸的是,出现以下错误:
06-01 23:11:26.039: WARN/AppWidgetHostView(244): updateAppWidget 找不到任何视图,使用错误视图 06-01 23:11:26.039: WARN/AppWidgetHostView(244): android.widget.RemoteViews$ActionException: 视图:android.widget.LinearLayout没有方法:setBackgroundDrawable(android.graphics.Bitmap)
<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"
>
我希望能够根据用户的选择更改使用的背景绘制。例如,使用远程视图,我可以通过执行以下操作来更新TextView的颜色:
remoteView.setTextColor(R.id.text_view1, Color.WHITE);
然而,我发现对于我的线性布局的背景进行相同的操作比较困难。我尝试过以下方法:
remoteView.setBitmap(R.id.widget_main, "setBackgroundDrawable", ((BitmapDrawable) context.getResources().getDrawable(R.drawable.widget_background_dark_4x2)).getBitmap());
但是我遇到了以下错误:
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)
<<编辑>> 也尝试了这个:
Bitmap bitmap = ((BitmapDrawable)context.getResources().getDrawable(R.drawable.widget_background_light_4x2)).getBitmap();
remoteView.setBitmap(R.id.widget_main, "setBackgroundDrawable",bitmap );
但不幸的是,出现以下错误:
06-01 23:11:26.039: WARN/AppWidgetHostView(244): updateAppWidget 找不到任何视图,使用错误视图 06-01 23:11:26.039: WARN/AppWidgetHostView(244): android.widget.RemoteViews$ActionException: 视图:android.widget.LinearLayout没有方法:setBackgroundDrawable(android.graphics.Bitmap)