Android: Creating custom AppWidgets

App Widgets are very small scale application window that shows information updates to user and lies on home screen. It is nice feature on Android to show crucial application data at home screen with tiny space.

It can be updated periodically as configured in app widget meta data. It can also be updated when it is clicked or tapped.

There two types of design layout for app widgets such as

  1. Portrait widgets dimensions- 4×1 cells (80*4 by 100 * 1) dp, 3×3 ,  2×2
  2. Landscape widgets dimensions –  4×1 (106*4 by 74*1)dp, 3×3, 2×2

If you want to create custom app widget then you should follow some steps as following.

  1. Create MyAppWidget layout into … res/layout/myappwidget_layout.xml – it’s the actual widget layout that will be shown in home screen. Add, for example, a TextView in this layout.
  2. Create xml directory in path … MyProject/res/xml
  3. Add MyAppWidgetProviderInfo, metadata file, where you define attributes of Appwidget …/res/xml/my_appwidgetprovider_info.xml
  4. Create MyAppWidgetProvider extends AppWidgetProvider and handles events onEnable(),  onUpdate(….),  onReceive(...) etc. Here you implement the View updates logics.
  5. Declare app widget receiver/provider class in AndroidManifest.xml
  6. Run this app widget project and find the MyAppWidget in widgets list and install from there. Then you will find that in home screen.

References:

  1. Android App widget
  2. App Widget design guidelines
  3. Home screen widget
Advertisements

About M Moniruzzaman
A passionate software engineer, have been developing applications on various platforms such as Android, iPhone, .Net (C#) technologies and web based ASP.NET, PHP, JavaScript, jQuery technologies for more than 10 years. Especially I have expertise on developing applications for Android and iPhone, as well as service oriented, client-server based applications where clients will be reside on Android/iPhone that communicate with WCF(.NET) service hosted on server. I have completed certification in Microsoft Certified Professional Developer (MCPD) on .Net 4 . I have completed my graduation in -- B.Sc. (Engineering) in Computer Science and Engineering, ShahJalal University of Science and Technology, Bangladesh. Thanks, M. Moniruzzaman (Zaman)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: