本文介绍了如何使用材料设计挑选时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用material:1.3.0-alpha01来选择时间,我正在下面的IO中找到屏幕截图,这是我在材料io中找到的.
how to pick a time using material:1.3.0-alpha01, I am looking time picker following screenshot, which I found in material io.
我尝试过日期选择器正在运行
I tried date picker is working
物料日期选择器
//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()
推荐答案
要使用材料时间选择器,请将以下依赖项添加到项目的build.gradle文件中:
To use MATERIAL TIME PICKER, add the following dependency to your project's build.gradle file:
implementation 'com.google.android.material:material:1.3.0-alpha02'
科特林时间选择器使用的材料:1.3.0-alpha02
Kotlin time picker using material:1.3.0-alpha02
val timePickerDialog = MaterialTimePicker.newInstance();
timePickerDialog.show(requireActivity().supportFragmentManager, "fragment_tag");
// Types of formats for the time pickeer
timePickerDialog.setTimeFormat(TimeFormat.CLOCK_12H)//CLOCK_24H
timePickerDialog.setListener { dialog: MaterialTimePicker ->
val newHour = dialog.hour
val newMinute = dialog.minute
}
这篇关于如何使用材料设计挑选时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!