android studio中的多语言支持
我读书 它说我们必须使用这种格式:android studio中的多语言支持,android,multilingual,Android,Multilingual,我读书 它说我们必须使用这种格式: <resource type>-b+<language code>[+<country code>] 我必须使用条件吗?(如果是,怎么做?)…我不能很好地理解这个医生。是的。Android操作系统可以通过搜索res文件夹为用户从应用程序中选择最佳语言 例如,可以在res/values es/strings.xml中定义西班牙语字符串值 因此,如果用户在手机中将其主要语言设置为西班牙语,Android操作系统将首先从res/
<resource type>-b+<language code>[+<country code>]
我必须使用条件吗?(如果是,怎么做?)…我不能很好地理解这个医生。是的。Android操作系统可以通过搜索res文件夹为用户从应用程序中选择最佳语言 例如,可以在res/values es/strings.xml中定义西班牙语字符串值 因此,如果用户在手机中将其主要语言设置为西班牙语,Android操作系统将首先从res/values es/strings.xml文件夹中读取字符串,而不是从res/values/strings.xml文件夹中读取字符串
如果res/values es/strings.xml中缺少一些字符串,那么它将从res/values/strings.xml引用。Android将从项目的“res”目录加载文本和媒体资源。基于当前设备配置和区域设置 例如,如果代码加载名为
'R.string.title'
的字符串,Android将在运行时通过从匹配的'res/values'
目录加载相应的strings.xml
文件来为该字符串选择正确的值
AndroidAppProject/
res/
values/
strings.xml
values-es/
strings.xml
values-fr/
strings.xml
在运行时,Android系统根据当前为用户设备设置的语言环境使用适当的字符串资源集
现在,您可以使用以下命令从res文件夹加载特定的区域设置字符串:
getResources().getString(R.string.hello_world);
例如:
Configuration conf = getResources().getConfiguration();
conf.locale = new Locale("fr"); //french language locale
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
Resources resources = new Resources(getAssets(), metrics, conf);
/* get localized string */
String str = resources.getString(R.string.hello_world);
这将从values fr/
目录加载R.string.hello\u world
AndroidAppProject/
res/
values/
strings.xml
values-es/
strings.xml
values-fr/
strings.xml
见