Widgets have been an important part of Android since its inception and have resurfaced somewhat with Android 12. For your convenience developers easily create widgets, Google announced a new library for Jetpack Compose that cuts down on a lot of work.
The new library is called Jetpack Glance and you can start testing its version right now. alpha for create widgets sensitive
Easily create widgets
Widgets have been around on Android since time immemorial and therefore have a way to create them, but times are changing. Just as Google encourages the use of Jetpack Compose for the creation of application interfaces with a few lines of codeThe same now applies to widgets with the help of Glance, a new library that is released in alpha phase.
Jetpack Glance has just been born, so its capabilities are still somewhat limited. It’s possible define a widget that contains a series of basic elements such as boxes, rows, columns, texts, buttons, images or spaces, with the possibility of performing actions such as opening applications, activating services, etc. A Hello World widget is made up of these few lines:
class GreetingsWidget(private val name: String): GlanceAppWidget() {
@Composable
override fun Content() {
Text(text = "Hello $name")
}
}
class GreetingsWidgetReceiver: GlanceAppWidgetReceiver () {
replace glance value AppWidget = GreetingsWidget (“Glance”)
}
Jetpack Glance is based on the same philosophy as Jetpack Compose and, in fact, requires that the project have the dependencies of Jetpack Compose, as well as that you have installed the latest version of Android Studio.
Interested developers can find out more on the Android Developers developer site, including sample code on GitHub so they can see what’s possible without having to start from scratch.
More information | Google