Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the whole application language? [duplicate]

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:

  1. how to change the whole application language in Selected Language?

  2. After choose the language whenever I reopen the application its give previous chosen language?

like image 574
Nikhil Shende Avatar asked Mar 22 '18 08:03

Nikhil Shende


People also ask

How do I change the language on Kotlin?

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.

What is Android Studio 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.


1 Answers

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());
like image 179
Subin Babu Avatar answered Oct 10 '22 01:10

Subin Babu