gpt4 book ai didi

android - 如何使用 Material 设计来挑选时间?

转载 作者:行者123 更新时间:2023-12-02 13:03:12 27 4
gpt4 key购买 nike

如何使用 Material 选择时间:1.3.0-alpha01,我正在寻找时间选择器下面的截图,我在 Material io 中找到。
我试过日期选择器正在工作material time picker
Material 日期选择器

//Creating a MaterialDatePicker.Builder instance that gives us a single date selector.
val builder : MaterialDatePicker.Builder<*> = MaterialDatePicker.Builder.datePicker() // 1
//Building-up the MaterialDatePicker by calling a builder.build function
val picker : MaterialDatePicker<*> = builder.build() // 2
//Display the Material Date Picker.
picker.show(requireActivity().supportFragmentManager, picker.toString()) // 3
简单的时间选择器
  val cal = Calendar.getInstance()
val timeSetListener = TimePickerDialog.OnTimeSetListener { _, hour, minute ->
cal.set(Calendar.HOUR_OF_DAY, hour)
cal.set(Calendar.MINUTE, minute)
//textView.text = SimpleDateFormat("HH:mm").format(cal.time)
}
val time = TimePickerDialog(context, timeSetListener, cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), true)
time.setTitle("")
time.show()

最佳答案

您可以使用新的 MaterialTimePicker 与 Material 组件库一起引入。
注:此代码 需要 至少版本 1.3.0-alpha03 .

import com.google.android.material.timepicker.MaterialTimePicker

val materialTimePicker = MaterialTimePicker.Builder()
.setTimeFormat(TimeFormat.CLOCK_24H)
.build()

materialTimePicker.addOnPositiveButtonClickListener {
val newHour: Int = materialTimePicker.hour
val newMinute: Int = materialTimePicker.minute
}
enter image description here
使用相同的代码:
val materialTimePicker = MaterialTimePicker.Builder()
.setTimeFormat(TimeFormat.CLOCK_12H)
.build()

materialTimePicker.show(supportFragmentManager, "fragment_tag")
enter image description here

关于android - 如何使用 Material 设计来挑选时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62882368/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com