I want to open datePicker
dialog on a button click in Jetpack compose.
For that, I am using the below code inside the button's onClick
action.
val context = LocalContext.current
Button(onClick = {
(context as AppCompatActivity).let {
val picker = MaterialDatePicker.Builder.datePicker().build()
picker.show(it.supportFragmentManager, picker.toString())
picker.addOnPositiveButtonClickListener {
// some code
}
}
})
If I am using the ComponentActivity
, supportFragmentManager
is not supported.
Is it fine to extend the activity from AppCompatActivity
?
Or is there any other way, I can get the solution if the above-mentioned solution is not correct?