我可以从不同区域的Andr​​oid访问的资源?区域、不同、资源、Andr

2023-09-05 00:33:02 作者:★宇ッ宙★

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

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.