Android kotlin library for change ui language in android application on runtime.
On your module app build.gradle
add
dependencies {
implementation 'com.ninenox.kotlinlocalemanager:kotlin-locale-manager:1.0.0'
}
- Create class and extend
ApplicationLocale
.
class App : ApplicationLocale() {
}
- In
AndroidManifest.xml
<application
android:name=".App"
...
/>
- In folder
res
add new locale.
values-th
- strings.xml
values-en
- strings.xml
- In any
Activity
extendAppCompatActivityBase
on it.
class MainActivity : AppCompatActivityBase() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
...
}
}
- Call funtion
setNewLocale("...")
for set current language and refresh UI.
setNewLocale("EN") // Sample "EN","TH","DE"...
- Get current code language string.
LocaleManager(this).language.toString() // "EN"