Change app language programmatically in Android

前端 未结 30 2967
面向向阳花
面向向阳花 2020-11-21 04:34

Is it possible to change the language of an app programmatically while still using Android resources?

If not, is it possible to request a resource in an specific lan

30条回答
  •  执念已碎
    2020-11-21 05:25

    /*change language at Run-time*/
    //use method like that:
    //setLocale("en");
     public void setLocale(String lang) { 
      myLocale = new Locale(lang);         
      Resources res = getResources();         
      DisplayMetrics dm = res.getDisplayMetrics();         
      Configuration conf = res.getConfiguration();         
      conf.locale = myLocale;         
      res.updateConfiguration(conf, dm);         
      Intent refresh = new Intent(this, AndroidLocalize.class);         
      startActivity(refresh); 
     }
    

提交回复
热议问题