[null,null,["最后更新时间 (UTC):2025-08-21。"],[],[],null,["# Android 12 widgets improvements\n\nAndroid 12 (API level 31) revamps the existing [Widgets\nAPI](/guide/topics/appwidgets/overview) to improve the user and developer\nexperience in the platform and launchers. Use this guide to learn how to ensure\nyour widget is compatible with Android 12, and also as a reference for APIs for\nrefreshing your existing widget.\n\nEnsure your widget is compatible with Android 12\n------------------------------------------------\n\nWidgets in Android 12 have rounded corners. When an app widget is\nused on a device running Android 12 or higher, the launcher\nautomatically identifies the widget's background and crops it to have rounded\ncorners.\n\nIn this scenario, your widget may not display properly in either of the\nfollowing conditions:\n\n- **The widget contains content in the corners**: This may cause some content\n in the corner area to be cropped.\n\n- **The widget uses a background that is not susceptible to cropping**. This\n includes a transparent background, empty views or layouts, or any other kind\n of special background not prone to cropping. The system may not be able to\n correctly identify the background to use.\n\nIf your widget will be affected by this change, we recommend refreshing it with\nrounded corners (as described in the following section) to ensure it displays\nproperly.\n| **Caution:** The dimensions of rounded corners may vary across devices because the size of the corner radius is controllable by both device manufacturers (up to 16dp) and third-party launchers. We recommend refreshing the widget to help avoid unsatisfactory results.\n\n### Use the sample\n\nTo see all these APIs in action, check out our [sample list widget](https://github.com/android/user-interface-samples/tree/main/AppWidget).\n\nImplement rounded corners\n-------------------------\n\n| **Note:** This guidance may be outdated. Refer to [Implement\n| rounded corners](/guide/topics/appwidgets#rounded-corner) for the latest guidance.\n\nAndroid 12 introduces the [`system_app_widget_background_radius`](/reference/android/R.dimen#system_app_widget_background_radius)\nand [`system_app_widget_inner_radius`](/reference/android/R.dimen#system_app_widget_inner_radius)\nsystem parameters to set the radii of your widget's rounded corners.\n**Figure 1:**Rounded corners on a widget and a view inside the widget\n\n1 Corner of the widget.\n\n2 Corner of a view inside the widget.\n\nFor details, see [Implement rounded corners](/guide/topics/appwidgets#rounded-corner).\n\nAdd device theming\n------------------\n\nStarting in Android 12, a widget can use the device theme colors\nfor buttons, backgrounds, and other components, including light and dark themes.\nThis enables smoother transitions and consistency across different widgets.\n\nSee [Add device theming](/guide/topics/appwidgets/enhance#dynamic-colors) for more information.\n**Figure 2:**Widget in light theme **Figure 3:**Widget in dark theme\n\n\u003cbr /\u003e\n\nMake it easier to personalize widgets\n-------------------------------------\n\nIf you specify a configuration activity with the [`configure`](/reference/android/appwidget/AppWidgetProviderInfo#configure) attribute of\n[`appwidget-provider`](/reference/android/appwidget/AppWidgetProviderInfo),\nthe App Widget host launches that activity immediately after a user adds the\nwidget to their home screen.\n\nAndroid 12 adds new options to let you provide a better\nconfiguration experience for users. See [Enable users to configure\nwidgets](/guide/topics/appwidgets/configuration) for details.\n\nAdd new compound buttons\n------------------------\n\nAndroid 12 adds new support for stateful behavior using the\nfollowing existing components:\n\n- [`CheckBox`](/reference/kotlin/android/widget/CheckBox)\n\n- [`Switch`](/reference/android/widget/Switch)\n\n- [`RadioButton`](/reference/android/widget/RadioButton)\n\nThe widget is still stateless. Your app must store the state and register for\nstate change events.\n**Figure 4:**Example widget with checkboxes\n\nFor details, see [Support for stateful behavior](/guide/topics/appwidgets#stateful-behavior).\n\nUse improved APIs for widget sizes and layouts\n----------------------------------------------\n\nStarting in Android 12, you can can take advantage of more refined size\nattributes and more flexible layouts, by specifying additional widget sizing\nconstraints and by providing responsive layouts and exact layouts.\n\nSee [Provide flexible widget layouts](/guide/topics/appwidgets/layouts) for details.\n\nImprove your app's widget picker experience\n-------------------------------------------\n\nAndroid 12 enables you to improve the widget picker experience\nfor your app by adding dynamic widget previews and widget descriptions. For\ndetails, see [Add scalable widget previews to the widget\npicker](/guide/topics/appwidgets/enhance#add-scalable-widget-previews) and [Add a description for\nyour widget](/guide/topics/appwidgets/enhance#add-widget-description).\n\nEnable smoother transitions\n---------------------------\n\nStarting in Android 12, launchers provide a smoother transition\nwhen a user launches your app from a widget. See [Enable smoother\ntransitions](/guide/topics/appwidgets/enhance#enable-smoother-transitions) for details.\n\nUse simplified `RemoteViews` collections\n----------------------------------------\n\nAndroid 12 adds the\n[`setRemoteAdapter(int viewId, RemoteViews.RemoteCollectionItems items)`](/reference/android/widget/RemoteViews#setRemoteAdapter(int,%20android.widget.RemoteViews.RemoteCollectionItems))\nmethod, which lets your app pass along a collection directly when populating a\n[`ListView`](/reference/android/widget/ListView). Previously, when using a\n`ListView`, it was necessary to implement and declare a\n`RemoteViewsService` to return\n[`RemoteViewsFactory`](/reference/android/widget/RemoteViewsService.RemoteViewsFactory).\n\nFor details, see [Use `RemoteViews` collections](/guide/topics/appwidgets/collections#use-remote-collections).\n\nUse runtime modification of `RemoteViews`\n-----------------------------------------\n\nAndroid 12 adds several `RemoteViews` methods that allow for runtime\nmodification of `RemoteViews` attributes. See the `RemoteViews` API reference\nfor the full list of added methods.\n\nFor details, see [Use runtime modification of\n`RemoteViews`](/guide/topics/appwidgets/enhance#use-runtime-mod-of-remoteviews)."]]