I'm developing a multi language app and I'm using code below and it was working well but now it has problem in android api 24 and below without any error. it just translate strings but I need my app be rtl. what should I use instead of my code?
fun setNewLocale(mContext: Context, language: String): Context {
setLanguagePref(mContext, language)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return updateResources(mContext, getLanguagePref(mContext)!!)
}
return updateResourcesLegacy(mContext, getLanguagePref(mContext)!!)
}
@TargetApi(Build.VERSION_CODES.N)
private fun updateResources(context: Context, language: String): Context {
val locale = Locale(language)
Locale.setDefault(locale)
val configuration = context.resources.configuration
configuration.setLocale(locale)
return context.createConfigurationContext(configuration)
}
private fun updateResourcesLegacy(context: Context, language: String): Context {
val locale = Locale(language)
Locale.setDefault(locale)
val resources = context.resources
val configuration = resources.configuration
configuration.locale = locale
resources.updateConfiguration(configuration, resources.displayMetrics)
return context
}