ANDROID: What is the main idea behind of using strings.xml?

后端 未结 2 760
不知归路
不知归路 2021-01-18 23:54

Someone please explain what is the main idea of using strings.xml? I think it would be useful for multi-language support but how can we organise it for that

2条回答
  •  猫巷女王i
    2021-01-19 00:51

    Hard-coding strings is Bad.

    Parameterizing strings (e.g. with strings.xml) is Good.

    Being able to internationalize your strings (with language and/or locale-specific versions of strings.xml) is even Better :)

    PS:

    To make use of internationalization, just create resource subdirectories. Google will give you plenty of references/examples. Herre's one:

    http://developer.android.com/guide/topics/resources/localization.html

    * res/values/strings.xml   
      Contains English text for all the strings that the application
      uses, including text for a string named title.
    
    * res/values-fr/strings.xml 
      Contain French text for all the strings, including title.
    
    * res/values-ja/strings.xml
      Contain Japanese text for all the strings...
    

    And yes, you should absolutely get in the habit of using strings.xml (and colors.xml and dimens.xml etc etc) even if you don't plan on internationalizing immediately.

    IMHO....

提交回复
热议问题