我想展示一个小部件,在小部件空间加载一个已经工作的碎片。我似乎找不到任何处理将碎片加载到小部件中的文档?有人能帮忙吗?
widget_current.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/widgetCurrent" />
</LinearLayout>
widget_provider.xml
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="40dp"
android:minHeight="40dp"
android:updatePeriodMillis="86400000"
android:initialLayout="@layout/widget_current"
android:resizeMode="horizontal|vertical"
android:widgetCategory="home_screen">
</appwidget-provider>
UpcomingEventWidgets.kt
class UpcomingEventsWidget: AppWidgetProvider() {
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
super.onUpdate(context, appWidgetManager, appWidgetIds)
val remoteView = RemoteViews(context.packageName, R.layout.widget_current)
appWidgetManager.updateAppWidget(appWidgetIds, remoteView)
}
}
如何将片段加载到 RemoteView 中?