Widget Creating in Android Studio

App Widgets are miniature application views that can be embedded in other applications (such as the Home screen) and receive periodic updates. These views are referred to as Widgets in the user interface, and you can publish one with an App Widget provider. An application component that is able to hold other App Widgets is called an App Widget host.



The Basics


To create an App Widget, you need the following:

AppWidgetProviderInfo object
Describes the metadata for an App Widget, such as the App Widget’s layout, update frequency, and the AppWidgetProvider class. This should be defined in XML.
AppWidgetProvider class implementation
Defines the basic methods that allow you to programmatically interface with the App Widget, based on broadcast events. Through it, you will receive broadcasts when the App Widget is updated, enabled, disabled and deleted.

Adding the AppWidgetProviderInfo Metadata


The AppWidgetProviderInfo defines the essential qualities of an App Widget, such as its minimum layout dimensions, its initial layout resource, how often to update the App Widget, and (optionally) a configuration Activity to launch at create-time. Define the AppWidgetProviderInfo object in an XML resource using a single <appwidget-provider> element and save it in the project’s res/xml/ folder.




Declaring an App Widget in the Manifest


First, declare the AppWidgetProvider class in your application’s AndroidManifest.xml file. For example:

Creating the App Widget Layout


You must define an initial layout for your App Widget in XML and save it in the project’s res/layout/ directory. You can design your App Widget using the View objects listed below, but before you begin designing your App Widget, please read and understand the App Widget Design Guidelines.

Using the AppWidgetProvider Class


You can download full code from here, You can modify the code us u like. In like manner feel free to comment your doubt’s below.¬†Does our tutorials help you then help as spread the word, like and share. More details available here.

Leave a Reply

%d bloggers like this: