CS4521:   Mobile and Topics in Web Programming

Android Strings

 

You can certainly hardcode or read in strings from a file, however, Android has a set of special locations for you to store your strings and gives you a way in your XML files to refer to them.

  • res/values/strings.xml = location of xml file that contains the default language (English) strings. Here is a simple example:
    <?xml version="1.0" encoding="utf-8"?>
    <resources>

    <string name="hello">This is my unique message saying ...Android is great</string> <string name="app_name">Lab1_4521</string> </resources>
  • res/values-fr/strings.xml = location of fr (French) language specific strings.

 

HOW to identify strings in such files:

  • @string/hello or @string/app_name in the above strings.xml file example. Generally --- @string/string_name

Recommendation: store all your string contants in your application in strings.xml file ---then translate and put in language/country specific directories res/values-LANGUAGE

 

TIP: If you do the above and the default language of the phone is French it will load and use the strings.xml file in res/values-fr

© Lynne Grewe