Multi language android app during Runtime?

橙三吉。 提交于 2019-11-29 17:25:22

I can give you idea how you can implement this:

step 1: make string file for all texts in values directory as string-ch, ch is the code for Chinese language. and in code get every string with the getResources.getString(R.string.text_name); so that it can take string value at run time either English or Chinese.

step 2: now create method :

void changeLanguage(String language) {
        Locale locale = new Locale(language);
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        getBaseContext().getResources().updateConfiguration(config,
                getBaseContext().getResources().getDisplayMetrics());
    }

step 3: call this method where you want to change language suppose if you want to get changed language of you application according to device language then you can call as:

changeLanguage(Locale.getDefault().getLanguage());
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!