Can I access to resources from different locale android?

前端 未结 4 1580
执念已碎
执念已碎 2020-12-01 19:26

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

4条回答
  •  暖寄归人
    2020-12-01 19:40

    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.

提交回复
热议问题