Material 不同设备上的日期选择器格式不同
Material Date Picker Difference Format on Difference Device
我需要帮助。
我正在使用日期选择器 material.io。
在不同的设备上安装 APK 时,我得到了不同的格式。
我发现问题出在语言设备设置上。
也许这里有人和我有同样的问题?如何解决这个问题?
这是我的日期选择器代码:
private val datePicker = MaterialDatePicker.Builder.datePicker().build()
with(datePicker) {
addOnCancelListener { datePicker.dismiss() }
addOnPositiveButtonClickListener {
val formatter = DateTimeFormatter.ofPattern("MMM d, yyyy")
datePickerValue = LocalDate.parse(datePicker.headerText, formatter)
binding.rowInputSearchDob.edtDob.setText(datePickerValue withFormat getString(R.string.date_format_d_MMM_yyyy))
}
}
先致谢:)
您的日期格式器和解析器将使用设备的格式和语言设置..“默认”语言环境。
要覆盖它,您需要指定语言环境。可能通过使用“.withLocale”参见 withLocale docs
我需要帮助。 我正在使用日期选择器 material.io。 在不同的设备上安装 APK 时,我得到了不同的格式。 我发现问题出在语言设备设置上。 也许这里有人和我有同样的问题?如何解决这个问题?
这是我的日期选择器代码:
private val datePicker = MaterialDatePicker.Builder.datePicker().build()
with(datePicker) {
addOnCancelListener { datePicker.dismiss() }
addOnPositiveButtonClickListener {
val formatter = DateTimeFormatter.ofPattern("MMM d, yyyy")
datePickerValue = LocalDate.parse(datePicker.headerText, formatter)
binding.rowInputSearchDob.edtDob.setText(datePickerValue withFormat getString(R.string.date_format_d_MMM_yyyy))
}
}
先致谢:)
您的日期格式器和解析器将使用设备的格式和语言设置..“默认”语言环境。 要覆盖它,您需要指定语言环境。可能通过使用“.withLocale”参见 withLocale docs