我的应用程序中有两种语言urdu和英语,当我选择英语时,它会显示英文日历,而urdu选择时却是英语,但是我想在选择urdu时显示英文日历,所以我想修正日历对话框的语言区域设置设置为urdu calendar will英语。我用这个,但没什么改变
Locale.setDefault(Locale.ENGLISH);
我该如何做到
calendar view screenshot 我使用> Locale.setDefault(Locale.ENGLISH); 但这并没有改变月份语言的任何建议我该如何实现
答案 0 :(得分:0)
您需要正确设置区域设置
第一项活动:
LocaleHelper.updateApplicationContextLocale(applicationContext, localeConfiguration, locale)
LocaleHelper.updateApplicationContextLocale
是:
fun updateApplicationContextLocale(applicationContext: Context,
localeConfiguration: Configuration,
locale: Locale) {
applicationContext.resources.updateConfiguration(localeConfiguration,
applicationContext.resources.displayMetrics)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
applicationContext.createConfigurationContext(localeConfiguration)
} else {
Locale.setDefault(locale)
val config = applicationContext.resources.configuration
config.locale = locale
applicationContext.resources.updateConfiguration(config,
applicationContext.resources.displayMetrics)
}
}
和
override fun getLocaleConfiguration(): Configuration {
val config = Configuration()
val locale = locale
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
config.setLocale(locale)
} else {
config.locale = locale
}
return config
}
override fun getLocale(): Locale {
return Locale(currentLanguageCode)
}