Change app language programmatically in Android

前端 未结 30 2975
面向向阳花
面向向阳花 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:11

    First you create directory name values-"Language name" like hindi than write "hi" and same string file name copy in this directory and change value do not change parameter after set below code in your action like button etc....

    Locale myLocale = new Locale("hi");
    Resources res = getResources();
    DisplayMetrics dm = res.getDisplayMetrics();
    Configuration conf = res.getConfiguration();
    conf.locale = myLocale;
    res.updateConfiguration(conf, dm);
    Intent refresh = new Intent(Home.this, Home.class);
    startActivity(refresh);
    finish(); 
    

提交回复
热议问题