头图

Author/Developer Relations Engineer Marcel Pintó Biescas, @marxallski

Android 12 improves , which is regarded as a key feature by many Android users- App Widgets . The improved Widgets are more practical, beautiful, and easier to be discovered by users (84% of users use at least one Widgets). Now, we have released the Jetpack Glance , which makes the building process of Widgets easier. This version is built on the new framework of Jetpack Compose runtime (Runtime) Build App Widgets for the home screen or other interfaces faster and easier.

You are welcome to try and do share feedback .

Glance provides a new declarative Kotlin API, which is similar to the API you use in Jetpack Compose , which can help you build more beautiful adaptive App Widgets with less code.

△ Glance "Hello World" Widgets 示例

△ Glance "Hello World" Widgets example

class GreetingsWidget(private val name: String): GlanceAppWidget() {
    @Composable
    override fun Content() {
        Text(text = "Hello $name")
    }
}

class GreetingsWidgetReceiver : GlanceAppWidgetReceiver() {

    override val glanceAppWidget = GreetingsWidget("Glance")
}

working principle

Glance provides a set of basic components that can be combined to help you create a "clear" experience. Now, we will provide more App Widgets. Glance uses Jetpack Compose runtime (Runtime) to convert the combinable item into the actual RemoteViews and display it in App Widgets.

△ Glance 结构示意图

△ Glance structure diagram

This means that Glance needs enable Compose , and it relies on Runtime, Graphics, and the unit interface Compose layer , but it does not have direct interoperability with other existing Jetpack Compose interface elements Sex . However, you can share the state or any other logic in the app to create a clear interface.

Alpha version introduction

This initial version introduces the main API, which not only enables interoperability with existing RemoteViews, but also helps you build App Widgets.

The following is an overview of the content provided by the development library:

We will also introduce more features, such as default themes, better Android Studio support, and more. Stay tuned new version .

Note: Although the minimum SDK version is 21, the minimum compatible version currently supported by the Alpha version is SDK v23.

You can view the building a new Android App Widgets video in Android 12 for more details.

Glance Getting Started

You can view the example on GitHub to get started quickly. Glance can also be used in the latest stable version of Android Studio , but first you need to follow Jetpack Compose document to set up, because Glance depends on the Compose runtime (Runtime).

In addition, you can also view the advanced example AndroidX code base.

Write your own plugin, you can extend Android Gradle Plugin and customize your build according to your project needs!

ResponsiveAppWidget.kt demo

The Alpha version is an important opportunity for you to participate in the development of the API. Therefore, welcome to share your feedback to help us understand and further enhance your experience! You are also welcome to continue to follow us to learn more about the latest content.

Looking forward to your experience!

Welcome to click here to submit feedback to us, or share your favorite content or problems found. Your feedback is very important to us, thank you for your support!


Android开发者
404 声望2k 粉丝

Android 最新开发技术更新,包括 Kotlin、Android Studio、Jetpack 和 Android 最新系统技术特性分享。更多内容,请关注 官方 Android 开发者文档。