如何getResources()的getString()的作品的android [英] How getResources().getString() works android

查看:595
本文介绍了如何getResources()的getString()的作品的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关,例如有应用程序,它提供了多语言支持,在我的活动/ UI,我称之为 getResources()的getString(R.string.hello)中存在在strings.xml中,这样

 值\ strings.xml中
值儒\的strings.xml
 

现在叫 getResources()时,的getString(R.string.hello),需要根据系统语言环境来访问字符串,这样会不会有得到<$ C字符串$ C>值\ strings.xml中或值儒\的strings.xml

确实基于系统区域人们不必改变我的应用程序的语言环境(保持应用程序的语言环境相同的系统区域),然后reterive从的getString()的值,建议的东西在下面链接

  1. <一个href="http://stackoverflow.com/a/6526588/1225413">get-string-from-default-locale-using-string-in-specific-locale

  2. <一个href="http://stackoverflow.com/a/9475663/1225413">how-to-get-string-from-different-locales-in-android

我有搜索的各种环节,但没能找到解决办法

解决方案

  MyProject的/
    RES /
       值/
           的strings.xml
       值-ES /
           的strings.xml
       值-FR /
           的strings.xml
 

添加字符串值每个区域设置到相应的文件。

在运行时,Android系统使用适当的一套基于当前为用户的设备设置区域设置字符串资源。

有关使用资源本地化信息

<一个href="http://developer.android.com/guide/topics/resources/localization.html">http://developer.android.com/guide/topics/resources/localization.html

更多信息@

<一个href="http://developer.android.com/training/basics/supporting-devices/languages.html">http://developer.android.com/training/basics/supporting-devices/languages.html

另外,请检查下面的链接

<一个href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/4.3_r2.1/android/content/ContextWrapper.java/">http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/4.3_r2.1/android/content/ContextWrapper.java/

  86 @覆盖
87公共资源getResources()
88 {
89返回mBase.getResources();
90}
 

返回一个资源实例,为你的应用程序的包。

  332
333市民最终字符串的getString(INT渣油){
334回getResources()的getString(渣油)。
335}
 

返回一个本地化的字符串从应用程序的包的默认字符串表。 参数: 渣油资源ID字符串

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 that

values\strings.xml
values-ru\strings.xml

Now when calling getResources().getString(R.string.hello) and need to access string based on system locale, so will one get strings from values\strings.xml OR values-ru\strings.xml?

OR

does one need to change my app locale based on system locale (keep app locale same as system locale) and then reterive the value from getString(), something suggested in below links

  1. get-string-from-default-locale-using-string-in-specific-locale

  2. how-to-get-string-from-different-locales-in-android

I have searched various other links, but not able to find the solution

解决方案

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

这篇关于如何getResources()的getString()的作品的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆