Android – Creating your first widget

Android - Creating your first widget

Android widget Example : Android widgets are used for many purposes. You can use widgets for displaying quick calendar, calculator, a simple do to list, etc. It is unique feature of Android OS. Android widgets are created by extending the android.widget class.

You can create your own widgets in Android application to display overview of information stored or used by the application. For example weather widget can display weather forecast of weeks or notepad application can display a note created by the user.

In this post I’ll showing steps to make your first android widget application.

Android widget Example –

To start creating your first android widget follow this steps :

Step 1 : Creating the project.

Make a new android project with package name : parallelcodes.simplewidget and with name : SimpleWidget. You can always use your own desired package name and application name.

Used : Android Studio

Minimum Required SDK : API 8 – Android Froyo

Target SDK : API 19 – Android Kitkat.

Step 2 : Creating widget provider XML file.

2.1 – Make a new folder named xml  in your res resource folder  “res->xml”

2.2 – Create a new xml file in the newly created xml folder with name : mywidgetprovider.xml


And edit it as following code :


<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android=""
android:updatePeriodMillis="0" >


This file defines the xml layout info of our application widget.

Step 3 : Creating the layout of our widget.

My default the activity_main.xml layout file will be created in your res->layout folder. If it is not created, please create one and edit it as following :

res->layout->activity_main.xml :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=""
android:background="#fff" >

android:text="Hello world!"
android:textSize="35dp" />


The widget will display a simple “Hello world” message upon using it. When you launch the widget, a simple Text message will be shown on your home screen. You can change the above file with your message or add a button or an image to it. This is the layout resource file of our application widget.

After making the layout, our widget will look like below image :

android widget example

Android – Creating your first widget Image 1

Step 4 : Coding the application.

Inside your project, under the src folder will be made during the creation of project. If it is not made make one as src>Packagename> (your package name) and edit it as following :

package parallelcodes.simplewidget;

import android.appwidget.AppWidgetProvider;

public class MainActivity extends AppWidgetProvider{


Step 5 : Editing the Manifest file.

Now finally open the Android manifest file and edit it as following :

AndroidManifest.xml :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
android:versionName="1.0" >

android:targetSdkVersion="14" />

android:theme="@style/AppTheme" >
<receiver android:name=".MainActivity">

<action android:name="android.appwidget.action.APPWIDGET_UPDATE"></action>

<meta-data android:name="android.appwidget.provider"



Now we can run our application. Let’s see a demo video of the application we just created :



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.