I am making an app in which I want to have a page where I show a language selection page. So far I've included English, Hindi, and Marathi, with English set as the default.
My question is:
how to change the whole application language in Selected Language?
After choose the language whenever I reopen the application its give previous chosen language?
You can use setTitle(getString(R. string. settings)) in onCreate of activity to update label. As for your second question, you can set dLocale from anywhere you want but you will need to restart you current activity and all other activities in back stack to update their language.
Android Studio provides first-class support for Kotlin. It even has built-in tools to help you convert Java-based code to Kotlin. The Show Kotlin Bytecode tool lets you to see the equivalent Java-based code as you learn Kotlin.
Put your all text in String file. For each language create separate String file(Deutsch values-de/strings.xml, French values-fr/strings.xml) and while you need to change language call following function. For English language set "en" for another set corresponding key
#Kotlin
val config = resources.configuration
val locale = Locale("en")
Locale.setDefault(locale)
config.locale = locale
resources.updateConfiguration(config, resources.displayMetrics)
#Android Java
Configuration config = getBaseContext().getResources().getConfiguration();
Locale locale = new Locale("en");
Locale.setDefault(locale);
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With