Android Adventures - Resources
Written by Mike James   
Thursday, 25 June 2015
Article Index
Android Adventures - Resources
Drawables, Values and IDs
Conditional Resources
Summary

 

Summary

 

  • Use resources for as much data as you can. It makes it easier to change things.

  • You can use the property window to create and use resources or you can edit the XML directly.

  • There is a wide range of resource types. In addition to layouts and menus, you are certain to use values and drawables.

  • Drawables are an example of a resource that doesn't use an XML file - you simply copy the graphics resource files into the drawables directory. 

  • You can store simple data types in the values resource directory and this is often a better way to do things than using constants in the code.

  • The R object is automatically generated and its structure mimics the resource directory structure. For each resource the R object has an integer resource id.

  • Many methods take a resource's id and retrieve the resource for you. If you want to explicitly access a resource in code then use the methods that the Resources object provides.

  • Conditional resource allow you to provide resources that suite the current device - locale, screen resolution and so on. 

  • Conditional resources work by applying qualifiers to the names of the directories that hold the resource files, e.g. values-es/.

  • Android Studio provides a simplified view of conditional resources that groups all variations on a resource file in the same abstract directory. This does not correspond to the file structure but it is simpler.

  • You can use Android Studio's New, Resource File command to create conditional resources.

  • The layout editor lets you select which locale resource is used so that you can work directly with the localized layout. 

  • If you want to localize your app then make use of the Android Studio Translation Editor.

 

 Translate

androidJavaSmallAndroid Programming In Java:
Starting With an App
Third Edition

Is now available in paperback and ebook.

Available from Amazon.

 

 

  1. Getting Started With Android Studio 3
  2. The Activity And The UI
  3. Building The UI and a Calculator App
  4. Android Events
         Extract: Using Lambdas
  5. Basic Controls
  6. Layout Containers
  7. The ConstraintLayout
        Extract: Guidelines and Barriers
  8. UI Graphics A Deep Dive
        Extract: Programming the UI ***NEW
  9. Menus & The Action Bar
  10. Menus, Context & Popup
  11. Resources
  12. Beginning Bitmap Graphics
        Extract: Simple Animation
  13. Staying Alive! Lifecycle & State
  14. Spinners
  15. Pickers
  16. ListView And Adapters

If you are interested in creating custom template also see:

Custom Projects In Android Studio

Androidgears

 

 

To be informed about new articles on I Programmer, install the I Programmer Toolbar, subscribe to the RSS feed, follow us on, Twitter,FacebookGoogle+ or Linkedin,  or sign up for our weekly newsletter.

 

espbook

 

Comments




or email your comment to: comments@i-programmer.info



Last Updated ( Tuesday, 11 October 2016 )