过去的两天里,我一直在努力根据某些if语句(现在已经删除了,只想从类中更改widget背景)来更改widget的背景。这是我的源代码。但是,问题是我以前可以更改图像,比如背景,但是现在无法将其应用于我的widget。谢谢。顺便说一句,这是我最近的尝试。
//Widget Provider Class
public class WidgetProvider extends AppWidgetProvider {
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final int N = appWidgetIds.length;
for (int i=0; i<N; i++) {
int appWidgetId = appWidgetIds[i];
Intent intent = new Intent(context, com.widget.WidgetDialog.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
views.setOnClickPendingIntent(R.id.widget, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
views.setImageViewBitmap(R.id.widget, ((BitmapDrawable)context.getResources().getDrawable(R.drawable.widget_background)).getBitmap());
}
}
}
//Widget Layout XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:id="@+id/widget"
android:background="#00000000"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</Button>
</LinearLayout>