How to pick time using material design?

前端 未结 2 1687
醉酒成梦
醉酒成梦 2021-01-16 10:20

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

M

相关标签:
2条回答
  • 2021-01-16 10:38

    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'
    

    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
    }
    
    0 讨论(0)
  • 2021-01-16 10:52

    You can use the new MaterialTimePicker introduced with the Material Components Library.

    Note: this code requires at least the version 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
    }
    

    Using the same code with:

    val materialTimePicker = MaterialTimePicker.Builder()
        .setTimeFormat(TimeFormat.CLOCK_12H)
        .build()
    
    materialTimePicker.show(supportFragmentManager, "fragment_tag")
    

    0 讨论(0)
提交回复
热议问题