Я разрабатываю мультиязычное приложение и использую приведенный ниже код, и он работал хорошо, но теперь у него есть проблемы в Android Api 24 и ниже без каких-либо ошибок. он просто переводит строки, но мне нужно, чтобы мое приложение было RTL. что я должен использовать вместо моего кода?
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
}