4

I want user to select a language inside the app. Once the language is selected, I want the strings to use the particular language.

If I change the phone language, then my app runs on the set language.

I am not able to find any way to set a language without changing the phone language. In addition, the changes should be reflected once the language is set.

Could anyone please suggest a way to do it?

5
  • Kindly use localisation in app Commented Oct 9, 2016 at 10:50
  • @JhamanDas actually I am a newbie to localization. Could you please share resource guide, link or something? Commented Oct 9, 2016 at 10:53
  • yes sure, make strings file like fi u want to use arabic language create values-ar folder and created strings resource file Commented Oct 9, 2016 at 10:55
  • Try to read this first. stackoverflow.com/a/12954037/4198633 and stackoverflow.com/a/10596034/4198633. This should do the trick... Commented Oct 9, 2016 at 10:55
  • 1
    stackoverflow.com/questions/2900023/… Commented Oct 9, 2016 at 10:56

1 Answer 1

8

Try this

public static void changeLang(Context context, String lang) { Locale myLocale = new Locale(lang); Locale.setDefault(myLocale); android.content.res.Configuration config = new android.content.res.Configuration(); config.locale = myLocale; context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics()); } 

Lang parameter should be "en" for English, "it" for Italian... After that you should restart your activity/fragment

Sign up to request clarification or add additional context in comments.

9 Comments

What's the best way to restart the activity? And how can I implement this into settings?
@Avi, just simply called recreate() in Activity after changing the language.
Without recreating activity or fragment is it possible?@aloj, @Sam
@MaulikDodia yes, it is possible. aloj code does work!
The solution just work in the current activity, if you back to the previous activity it doesn't work any more.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.