Free Android app covering all aspects of addiction, including prevention and treatment

Localizing your resources

Keeping it local

Android localisation icon

Android apps can be installed on devices around the world. If you want to distribute your app to this large market, then you should provide alternative resources such as text, sound and images.

Android makes it easy to include alternative strings, sound files, layouts and images so that your app will work in any country and in any language.

Our tutorial app will show you how to include alternative text and image resources.

Using your application resources

Application Resources icon

You should keep your resources, like images, strings, values, etc. separate from your code.

Application Resources folders

Some of the folders in the res directory

Different images for different devices: it’s all about supply and demand

Android alternative bitmap resources logoThis is the 2nd part of a two part series of articles on designing Android apps for multiple screens. Here's a link to part 1, Different images for different devices: bitmaps, pixels and other things that go bump in the night

Put all images that you use in an Android app inside a drawable folder. You should also supply different size images for the different screen densities.

Alternative bitmaps

Android devices come in different shapes and sizes. Their screen sizes range from small phones to 10 inch tablets and larger TV’s. They also have different screen densities.

Different images for different devices: bitmaps, pixels and other things that go bump in the night

resources icon

Which images to use as image resources

There are two main graphic types, bitmap and vector graphics.

Vector graphics describe an image according to its geometric characteristics and can be resized without losing quality.

In Android, we’re more interested in Bitmap images which are stored electronically as a map of bits.

Another electronic image term is the pixel. Sometimes bits and pixels are interchanged and a bitmap can refer to a map of pixels, where each pixel represents a colour.

Bitmaps are resolution dependent which means they contain a fixed number of pixels so they will lose quality if you change their size.

Application resources include images, text and music files. It is a good idea to store these in separate folders which makes it easier to maintain the code and to adapt your application for different languages and devices. You simply supply alternative resources for the different languages and devices and the system takes care of the rest.

Android for beginners Tutorials. Application Resources bundle describes the different types of resources that you can use and shows you where to put them. It also shows you how to use alternative resources so that your application can seamlessly work on different devices such as phones and tablets and also with different languages.

Android for beginners Tutorials. Application Resources bundle includes 19 detailed tutorials, with line-by-line commentary, putting the theory into practice.

The tutorials include:

  • View Animation Tutorial – this includes Frame animation where one image is swopped with another and Tweening, where for example some text fades in or out.
  • Color State List tutorial – this tutorial shows how a color state list is used to change the color of an object when it’s state changes.
  • Bitmap Tutorial –this tutorial shows how to use a bitmap both directly and via an alias.
  • Nine-Patch Tutorial – this tutorial demonstrates how to use a nine-patch drawable in an application. It shows how to use it directly from the drawable folder as well as how to define a nine-patch drawable in a XML file.
  • Layer List Tutorial – this tutorial demonstrates how to use a list of drawables saved in a XML file as a drawable object. When the app runs, the drawables in the list are displayed one above the other.
  • State List Tutorial – this tutorial shows how to use a State List to change the background image of a button when the button is pressed, in focused or in default mode.
  • Level List Tutorial - A level list is a drawable object that manages a number of alternative drawables. Each of these drawables is assigned a maximum level. We can then determine which drawable to use by usingsetLevel() in our code, passing it the appropriate level. The drawable with a level equal to or greater than this will be selected.
  • Transition Drawable Tutorial – this tutorial demonstrates how to use a Transition Drawable. A TransitionDrawable is a drawable object that cross-fades between two drawable resources.
  • Inset Drawable Tutorial – this demonstrates the Inset Drawable which we define in a XML file. We then reference it in the layout file to display a drawable in a view where the drawable is smaller than the view’s boundaries
  • Clip Drawable Tutorial – this tutorial demonstrates how to use a Clip Drawable as a simple progress bar.
  • Shape Drawable Tutorial – this tutorial shows how to create and use a Shape Drawable resource as a background image.
  • Layout Tutorial – this tutorial briefly describes the use of layouts.
  • Simple Resources Tutorial – this tutorial demonstrates how to combine a number of resources in one XML file. It covers the use of the following resources: Strings, String arrays, Plurals, Color, Dimensions, Integer arrays, Style, bool, integer and typed arrays.
  • Scale Drawable Tutorial - this tutorial shows how to use the Scale Drawable resource to increase the size of a drawable.
  • Options Menu Tutorial - this tutorial shows how to create a simple options menu.
  • Assets and Raw Files Tutorial - this tutorial demonstrates how to use files in their raw form either from the assets folder or from the res>raw folder.
  • XML File Tutorial - this tutorial shows how to use an XML resource file containing a number of records.
  • Localization Tutorial - this tutorial shows how to accommodate three different languages in an app.
  • Images, Rotation and Orientation Tutorial - This tutorial shows how one can allow for screen orientation changes and different size screens.

Once you have mastered these tutorials, you will feel comfortable creating great apps that will work on any device in any language.

This eBook assumes that you have at least completed the “Hello world” tutorial which can be found on the official Android website. All the tutorials have been written with Eclipse (Helios) as the development environment. Naturally you can use any other development environment.

Available at Amazon.com

 You can download the project files from the download page.