Android How-To Guide

Páginas: 12 (2896 palabras) Publicado: 18 de junio de 2012
How to: Android 'Hello Widget'
Table of Contents
Document history......................................................................................................1 HelloWidget...............................................................................................................1Prerequisites.........................................................................................................1 Let’s start from scratch..........................................................................................1 The Java-way Time-Widget..................................................................................6 The Service-way Time-Widget (not working with 1.6 any more)..........................8 How to use Buttons onWidgets................................................................................9 Prerequisites.........................................................................................................9 The Layout............................................................................................................9 AppWidget Provider............................................................................................10 Manifestfile.........................................................................................................10 ButtonWidget Provider........................................................................................11

Document history
Version 1.0 1.1 Date 2009-07-11 2009-07-21 User Norbert Möhring moehring.n [at] googlemail.com Norbert Möhring moehring.n [at] googlemail.com DescriptionInitial document. Small fixes in code (copy&paste erros ). Thanks to Andreas Kompanez (ak@endlessnumbered.com) for the review. Better layout. Added document history and table of contents. Put all links behind text → looks better  Fixed some typos - Some comments to the new 1.6 Version - How to use Buttons on widgets

1.2 1.3

2009-07-23 2009-09-27

Norbert Möhring moehring.n [at]googlemail.com Norbert Möhring moehring.n [at] googlemail.com

HelloWidget
Since there is only the one not that self explaining example of a widget I decided to invest some nightly hours to cut that example into pieces and then start from scratch with an easy to follow “Hello Widget” tutorial.

Prerequisites
You should already have the android SDK and android Eclipse IDE plug-in installed and running.If not, go here to learn how to get started with the android plug-in. Also you should have at least basic knowledge about Java programming since this is not a Java tutorial.

Let’s start from scratch
In Eclipse, go to File → new Project … → other … and select 'Android Project' The project name will be “Hello Widget” and in this case the target platform will be ‘Android 1.5’. Uncheck theprobably already checked Box “Create Activity”. We won’t create an Activity here we just want a simple widget.

How to: Android ‚Hello Widget’

Page 1 of 12

New Project Wizard

After that, your Project structure will look like this:

The project wizard gave us some default stuff already, like the default android app-icon e.g. We’ll start with the layout and design of our widget. Openmain.xml and modify it like this:


How to: Android ‚Hello Widget’

Page 2 of 12

We have a simple linear layout with a TextView for your message to display. At this point, you will get an Error saying ERROR Error: No resource found that matches the given name (at 'background' with value '@drawable/widget_bg_normal') That’s because you don’t have the widget_bg_normal resource at this point. Iborrowed the image from the SimpleWiktionary widget. It’s a png NinePatch image which will be our background of the widget. Put the file widget_bg_normal.9.png (or your own background image) into the folder res/drawable. You also don’t have the @string/widget_text resource. To fix that, go to res/values/string.xml and add this line to it:
Hello Widget!

string.xml will look like this:...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • How to
  • A guide to alausí
  • A guide to disturbing cinema
  • How to do surveys
  • How To Spot
  • How to basic
  • Pervert's guide to cinema
  • How to choose a pet?

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS