How can I change language of my application [duplicate] How can I change language of my application [duplicate] android android

How can I change language of my application [duplicate]


Use this to change the language programmatically:

Locale locale = new Locale("en_US"); Locale.setDefault(locale);Configuration config = new Configuration();config.locale = locale;context.getApplicationContext().getResources().updateConfiguration(config, null);

Write the country code of the language in place of "en_US" for whatever language you want. For example, for Japanese, ja_JP; for Arabic, ar. Check this link for a list.

And make a folder in res/values-ja for Japanese or res/values-ar for Arabic..

And make a string.xml file, and put whatever languages you want on your layout. It will fetch the default language from values folder otherwise if you want it manually, then it will fetch from your external folder values-ar, etc.

An example of res/values-ar for Arabic:

<?xml version="1.0" encoding="UTF-8"?>  <resources>    <string name="label">حسب</string>    <string name="name">بحث</string>     <string name="search">بحث :</string> </resource>


You can set the locale.

    Resources res = context.getResources();    // Change locale settings in the app.    DisplayMetrics dm = res.getDisplayMetrics();    android.content.res.Configuration conf = res.getConfiguration();    conf.locale = new Locale(language_code.toLowerCase());    res.updateConfiguration(conf, dm);

If you have language specific content - you can change that base on the setting.for more detail you can see Locale and this also