Widget Creating in Android Studio

widget-creating-in-android-studio-logicchip thump

App Widget 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 AppWidget provider. An application component that is able to hold other App Widgets is called an AppWidget host.

The Basics

To create an AppWidget, you need the following:

AppWidgetProviderInfo object
Describes the metadata for an AppWidget, 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 AppWidget, 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 AppWidget in XML and save it in the project’s res/layout/ directory. You can design your AppWidget using the View objects listed below, but before you begin designing your AppWidget, please read and understand the AppWidget 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: