Prerequisites: How to Create a Basic Widget of an Android App?
Widgets are the UI elements provided by an application for accessing some of its features remotely either from Home Screens or Lock Screens. Widgets can be Static or Dynamic meaning that the display elements don’t change (Static) or change (Dynamic) with time. Through this article, let’s demonstrate the implementation of a Dynamic widget. In our case, we shall change the display with respect to time using a Thread. Here is a preview of the same:
Steps for Creating Dynamic Widget
Step 1: Create a New Project
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Kotlin as the programming language.
Step 2: Add the App Widget to the Project
- Right-Click on the app, move the cursor to new, find the “Widget” option at the end, select it.
- Specify the required properties for the widget such as min.width and height, config file and preferred language, etc, and proceed. Files are automatically generated.
Step 3: What to program? Where to program?
- In our application, since we wish to display two messages “Just do it” & “You are awesome” (the users may choose their own messages) one after the other simultaneously, we would be implementing a thread for generating a pause (of 1 second) in between.
- The entire programming (back-end) is done in the newly created NewAppWidget.kt, Kotlin Class File in the Main Source Folder.
Changes made only to NewAppWidget.kt file
That’s it, run the code and you will see this widget in the Widgets list, bring it to Home Screen.
Output: Run on Emulator
- How to Create a Basic Widget of an Android App?
- How to Publish Your Android App on Amazon App Store for Free?
- How to Create Buttons Inside a Widget in Android?
- Android | Running your first Android app
- How to create a Facebook login using an Android App?
- How to create a Stopwatch App using Android Studio
- How to create a COVID-19 Tracker Android App
- How to create Swipe Navigation in an Android App
- How to create a Face Detection Android App using Machine Learning KIT on Firebase
- How to Create Static Shortcuts in Android App?
- How to Create a Quiz App In Android?
- How to Create a Morse Code Converter Android App?
- How to Create a COVID-19 Tracker Android App to See Details of any City and State in India?
- How to Create a Dark Mode for a Custom Android App in Kotlin?
- How to Create Dynamic Shortcuts of an Android Applications?
- Android | How to Create/Start a New Project in Android Studio?
- TextView widget in Android using Java with Examples
- EditText widget in Android using Java with Examples
- How to Add Widget of an Android Application?
- How to make a phone call from your Android App?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.