我在文档中看到:
EXTRA_APPWIDGET_PREVIEW
一个额外的,可以传递给requestPinAppWidget(android.content.ComponentName,android.os.Bundle,android.app.PendingIntent)。
所以我尝试了类似的东西:
...
Bundle b = new Bundle();
b.putInt(AppWidgetManager.EXTRA_APPWIDGET_PREVIEW, R.drawable.preview_new);
appWidgetManager.requestPinAppWidget(myWidgetProvider, b, successCallback);
但似乎捆绑b完全被忽略(它不会改变预览)。
我究竟做错了什么?
将Bundle替换为:Bundle b = new Bundle(); RemoteViews remoteViews = new RemoteViews(getPackageName(),R.layout.widget_layout); b.putParcelable(AppWidgetManager.EXTRA_APPWIDGET_PREVIEW,remoteViews);
参考:https://medium.com/wearebase/android-oreo-widget-pinning-in-kotlin-398d529eab28