You can use the locale class to do this .Hope this helps
public class LocaleLanguage { private static Locale mLocale; public static void setLocale(Locale locale) { mLocale = locale; if(mLocale != null) { Locale.setDefault(mLocale); } } public static void updateConfig(ContextThemeWrapper wrapper) { if(mLocale != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { Configuration configuration = new Configuration(); configuration.setLocale(mLocale); wrapper.applyOverrideConfiguration(configuration); } } public static void updateConfig(Application app, Configuration configuration) { if(mLocale != null && Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { //Wrapping the configuration to avoid Activity endless loop Configuration config = new Configuration(configuration); config.locale = mLocale; Resources res = app.getBaseContext().getResources(); res.updateConfiguration(config, res.getDisplayMetrics()); } } }
here is the application class
public class App extends Application { public void onCreate(){ super.onCreate(); // get user preferred language set locale accordingly new locale(language,country) LocaleUtils.setLocale(new Locale("iw")); LocaleUtils.updateConfig(this, getBaseContext().getResources().getConfiguration()); } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); LocaleUtils.updateConfig(this, newConfig); } }
here is the your activity
public class MainActivity extends Activity { public BaseActivity() { LocaleUtils.updateConfig(this); } }
And for more refer this link for whole tutorial refer this link