Android Programming In Kotlin: Resources
Written by Mike James   
Monday, 04 February 2019
Article Index
Android Programming In Kotlin: Resources
Conditional Resources
Conclusion

Working with Android Studio you can, for the most part, ignore the actual file and directory structure and simply add additional resource files using the New Resource File dialog, or for adding locales the Translation Editor described in the next section. Occasionally, however, you will need to find a file and manually edit the directory structure. In particular, there are no commands that allow you to modify the qualifiers associated with a resource file. The simplest solution is to delete the file and re-create it with new qualifiers if necessary. It is also worth mentioning that you can create custom layout files in the same way and that the Layout Editor also has facilities to allow you to clone an existing portrait layout as a landscape layout, for example.

A Simple Localization

Final version in book.

Android Studio Translation Tools

Final version in book.


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 resources allow you to provide resources that suit 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.

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

  • You can use the 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.

 

 

 

 

Android Programming In Kotlin
Starting with an App

Covers Android Studio 3 and Constraint Layout.

Is now available as a print book:

coverKotlinsmall

Buy from: Amazon

Contents

  1. Getting Started With Android Studio 3
  2. The Activity And The UI
        Extract: Activity & UI  
  3. Building The UI and a Calculator App
        Extract: A First App
  4. Android Events
  5. Basic Controls
        Extract Basic Controls
        Extract More Controls ***NEW!
  6. Layout Containers
        Extract Layouts - LinearLayout
  7. The ConstraintLayout 
        Extract Bias & Chains
  8. Programming The UI
        Extract Programming the UI
        Extract Layouts and Autonaming Components
  9. Menus & The Action Bar
  10. Menus, Context & Popup
  11. Resources
        Extract Conditional Resources
  12. Beginning Bitmap Graphics
        Extract Animation
  13. Staying Alive! Lifecycle & State
        Extract  State Managment
  14. Spinners
  15. Pickers
  16. ListView And Adapters
  17. Android The Kotlin Way

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, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

raspberry pi books

 

Comments




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

<ASIN:1871962544>

<ASIN:1871962536>

 



Last Updated ( Monday, 04 February 2019 )