Set Locale programmatically

后端 未结 14 1637
Happy的楠姐
Happy的楠姐 2020-11-22 05:55

My app supports 3 (soon 4) languages. Since several locales are quite similar I\'d like to give the user the option to change locale in my application, for instance an Itali

14条回答
  •  野性不改
    2020-11-22 06:14

    Put this code in your activity

     if (id==R.id.uz)
        {
            LocaleHelper.setLocale(MainActivity.this, mLanguageCode);
    
            //It is required to recreate the activity to reflect the change in UI.
            recreate();
            return true;
        }
        if (id == R.id.ru) {
    
            LocaleHelper.setLocale(MainActivity.this, mLanguageCode);
    
            //It is required to recreate the activity to reflect the change in UI.
            recreate();
        }
    

提交回复
热议问题