从RemoteViews查看实例,可以通过以下几个步骤:
RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.widget_layout);
remoteViews.setTextViewText(R.id.textView, "Hello World!");
remoteViews.setImageViewResource(R.id.imageView, R.drawable.example_image);
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
AppWidgetHost appWidgetHost = new AppWidgetHost(this, 1001);
int appWidgetId = appWidgetHost.allocateAppWidgetId();
AppWidgetProviderInfo appWidgetProviderInfo = appWidgetManager.getAppWidgetInfo(appWidgetId);
appWidgetHost.startListening();
appWidgetHost.createView(this, appWidgetId, appWidgetProviderInfo);
remoteViews.setTextViewText(R.id.textView, "New Text!");
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
appWidgetHost.deleteAppWidgetId(appWidgetId);
appWidgetHost.stopListening();
这些步骤可以帮助您从RemoteViews查看实例,并更新实例的显示内容。
领取专属 10元无门槛券
手把手带您无忧上云