简体   繁体   中英

Multilingual Not working For Date Picker Android

We have some issue with Date picker when change the locale of Android App. any one can help me out.

When we change the language of Device Francia(Canada) then app is working fine with this code

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        Locale.setDefault(resources.configuration.locales.get(0))
    }else{
        Locale.setDefault(resources.configuration.locale)
    }

but if we change the locale of app without change the device language from setting the getting incorrect result.

var locale=Locale(SharedPreferencesManager.getStringPreference(Constants.LOCALE, ""))
    Locale.setDefault(locale)
    val resources = resources
    val configuration = resources.configuration
    val displayMetrics = resources.displayMetrics

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        configuration.setLocale(locale)
        createConfigurationContext(configuration)
    } else {
        configuration.locale=locale
        resources.updateConfiguration(configuration, displayMetrics)
    }

Correct View

Incorrect View(Cancel and OK button not change as per app locale )

According to the http://code.google.com/p/android/issues/detail?id=25107 bug report on Android framework, the date picker is not using the String array of the shortened month of the Context of the app. Instead, it uses the System Locale.

You can use AppLocaleDatePickerDialog.java written by Gilbertwat.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM