Quantcast
Channel: User Mr.Goomer - Stack Overflow
Viewing all articles
Browse latest Browse all 42

Change Language Button

$
0
0

I am trying to create a button that changes the app language.I created the string file for the language and I tried this code for changing the default language but with no success:

public void changeLang(Context context, String language) {    Locale locale = new Locale(language);    Locale.setDefault(locale);    Configuration config = context.getResources().getConfiguration();    config.setLocale(locale);    context.createConfigurationContext(config);    context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());    restartActivity();}private void restartActivity() {    Intent intent = getIntent();    finish();    startActivity(intent);}

and this is how I called it:

changeLang(getApplicationContext(),"iw");

Thank you !


Viewing all articles
Browse latest Browse all 42

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>