Пожалуйста, проверьте этот обновленный ответ: -
В макете, который определил макет основного виджета, мне нужно было добавить следующее: android: id = "@ + id / LineaRLayout1"
затемв AppWidgetProvider onUpdate в конечном итоге выглядело так: все, что я на самом деле показываю, это то, как я изменил цвет
, просто замените id элемента на id вашего элемента.
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final int N = appWidgetIds.length;
Log.d(LOG_TAG, "Updating Example Widgets.");
// Perform this loop procedure for each App Widget that belongs to this
// provider
for (int i = 0; i < N; i++) {
int appWidgetId = appWidgetIds[i];
// Create an Intent to launch ExampleActivity
Intent intent = new Intent(context, WidgetActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
// Get the layout for the App Widget and attach an on-click listener
// to the button
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.activity_main);
//try change color here with no luck, I tried activity_main,background, widget1
views.setInt(R.id.LineaRLayout1, "setBackgroundColor", Color.GREEN);
views.setOnClickPendingIntent(R.id.button, pendingIntent);
// Tell the AppWidgetManager to perform an update on the current app
// widget
appWidgetManager.updateAppWidget(appWidgetId, views);