You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修复时间选择器对话框显示西班牙语的问题

时间选择器键盘界面语言异常问题

这是时间选择器的弹窗:
时间选择器弹窗

点击键盘图标后,显示如下界面:
时间选择器键盘界面

我们的APP支持本地化功能,以下是打开时间选择器弹窗的代码:

private fun openTimePickerDialog(datetime: String) {
    val mHour: Int = datetime.substring(8, 10).toInt()
    val mMinute: Int = datetime.substring(10, 12).toInt()
    setDefaultLanguage()
    Log.i("TAG", "openTimePickerDialog: $mHour $mMinute")
    val timePickerDialog = TimePickerDialog(
        activity,
        { _, hourOfDay, minute ->
            var selectedMinute = minute.toString()
            var selectedHour = hourOfDay.toString()
            if (minute < 10) {
                selectedMinute = "0$selectedMinute"
            }
            if (hourOfDay < 10) {
                selectedHour = "0$selectedHour"
            }
            isClickedDate = ""
            val date: String = datetime.substring(0, 8)
            val time = selectedHour + selectedMinute + "00"
            Log.i("TAG", "onTimeSet: $date$time")
            roveR3SettingFragmentViewModel.setDateTime(date + time)
            // txtTime.setText(hourOfDay + ":" + minute);
        }, mHour, mMinute, false
    )
    timePickerDialog.setButton(
        DatePickerDialog.BUTTON_POSITIVE,
        getString(R.string.ok),
        timePickerDialog
    )
    timePickerDialog.setButton(
        DatePickerDialog.BUTTON_NEGATIVE,
        getString(R.string.txt_cancel),
        timePickerDialog
    )
    timePickerDialog.show()
}

private fun setDefaultLanguage() {
    if (appPreference.appLanguage == LANGAUGE_ES) {
        val locale1 = Locale("en")
        Locale.setDefault(locale1)
        val config = requireContext().resources.configuration
        config.setLocale(locale1)
        requireContext().createConfigurationContext(config)
    } else if (appPreference.appLanguage == LANGAUGE_ES) {
        val locale1 = Locale("ja")
        Locale.setDefault(locale1)
        val config = requireContext().resources.configuration
        config.setLocale(locale1)
        requireContext().createConfigurationContext(config)
    }
}

我已将应用语言设置为英文,其他界面均正常显示英文,但点击时间选择器对话框的键盘图标后,界面却显示为西班牙语,求解决方法,谢谢。


内容的提问来源于stack exchange,提问作者MARSH

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 03:51:36