How getResources().getString() works android

前端 未结 2 438
野趣味
野趣味 2020-12-10 19:11

For e.g there is app which provides multi-language support, in my activity/UI, I call getResources().getString(R.string.hello) which exist in strings.xml,such t

2条回答
  •  隐瞒了意图╮
    2020-12-10 19:38

    MyProject/
        res/
           values/
               strings.xml
           values-es/
               strings.xml
           values-fr/
               strings.xml
    

    Add the string values for each locale into the appropriate file.

    At runtime, the Android system uses the appropriate set of string resources based on the locale currently set for the user's device.

    For info on Localizing with Resources

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

    More info @

    http://developer.android.com/training/basics/supporting-devices/languages.html

    Also check the below link

    http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.3_r2.1/android/content/ContextWrapper.java/

    86     @Override
    87     public Resources getResources()
    88     {
    89         return mBase.getResources();
    90     }
    

    Return a Resources instance for your application's package.

    332 
    333     public final String getString(int resId) {
    334         return getResources().getString(resId);
    335     }
    

    Return a localized string from the application's package's default string table. Parameters: resId Resource id for the string

提交回复
热议问题