我可以从不同区域的Andr​​oid访问的资源? [英] Can I access to resources from different locale android?

查看:119
本文介绍了我可以从不同区域的Andr​​oid访问的资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个区域在我的应用程序。我可以从不同的地区获取资源,例如字符串数组,而不改变当前的语言环境? 我的意思是有编码的,我不喜欢的设置进行更改。

I have two locale in my application. Can I access to resources, for example string array from different locale without to change current locale ? I mean with coding I don't like to change it in Settings.

推荐答案

下面是code,对于我的工作,如果CMK是从当前的语言环境字符串数组和CEN是字符串数组从不同势区域

Here is the code that work for me if cMK is String array from current locale and cEN is string array from diffrent locale

 cMK = getResources().getStringArray(R.array.cities);

         Configuration confTmp =new Configuration( getResources().getConfiguration());

         confTmp.locale = new Locale("en");

         DisplayMetrics metrics = new DisplayMetrics();

         getWindowManager().getDefaultDisplay().getMetrics(metrics);

         Resources resources = new Resources(getAssets(), metrics, confTmp);

         /* get localized string */
         cENG = getResources().getStringArray(R.array.cities);

目前的语言环境没有改变,这正是关键所在。

The current locale isn't changed and that was the point.

这篇关于我可以从不同区域的Andr​​oid访问的资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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