1

I want to use new MaterialDatePicker in my app

I have used below code to use MaterialDatePicker

val builder = MaterialDatePicker.Builder.datePicker()
builder.setTitleTextResId(R.string.date_of_birth)
builder.setTheme(R.style.MyTimePickerDialogTheme)
val picker = builder.build()
picker.show(childFragmentManager, picker.toString())

But MaterialDatePicker is not working as excepted

below is my dependencies

implementation 'com.google.android.material:material:1.1.0-alpha10'

**My current output**

**My expected output**

Another issue I'm facing is i don't know how to get selected date

Can anybody help me to solve these issues

If need more information please do let me know. Thanks in advance. Your efforts will be appreciated.

UPDATE i have tried solution provided in these post MaterialDatePicker not working on Android

Here is my MyTimePickerDialogTheme

<style name="MyTimePickerDialogTheme" parent="AppTheme">
    <item name="materialCalendarStyle">@style/Widget.MaterialComponents.MaterialCalendar</item>
    <item name="materialCalendarFullscreenTheme">@style/ThemeOverlay.MaterialComponents.MaterialCalendar.Fullscreen</item>
    <item name="materialCalendarTheme">@style/ThemeOverlay.MaterialComponents.MaterialCalendar</item>
</style>

Here is my AppTheme

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@android:color/white</item>
        <item name="colorPrimaryDark">@android:color/white</item>
        <item name="colorAccent">@color/colorAccent</item>
</style>

I'm still getting same output

Goku
  • 9,102
  • 8
  • 50
  • 81
  • @yuvrajsinh The question is about the [`MaterialDatePicker`](https://github.com/material-components/material-components-android/blob/master/docs/components/Picker.md) not the `android.app.DatePickerDialog` – Gabriele Mariotti Oct 02 '19 at 11:14
  • @GabrieleMariotti can please share demo how to use `materialCalendarStyle` i have added those `style` in my `AppTheme` still I'm getting same output Also i don't know how to get selected date – Goku Oct 02 '19 at 11:15
  • @GabrieleMariotti please check updated question – Goku Oct 02 '19 at 11:18
  • First of all you have to use a [`MaterialComponents.Theme`](https://github.com/material-components/material-components-android/blob/master/docs/getting-started.md#material-components-themes) in your App. the `materialCalendarStyle` is by default provided by it. You don't need to add theme. – Gabriele Mariotti Oct 02 '19 at 11:18
  • @GabrieleMariotti i'm already using `Theme.MaterialComponents.Light.NoActionBar` please check updated question – Goku Oct 02 '19 at 11:19
  • You don't need to add them. These attributes are defined by default in the material theme attributes. Remove the line `builder.setTheme(R.style.MyTimePickerDialogTheme)` – Gabriele Mariotti Oct 02 '19 at 11:25
  • @GabrieleMariotti i have removed `builder.setTheme(R.style.MyTimePickerDialogTheme)` but still getting same output is there something that i'm missing?? – Goku Oct 02 '19 at 11:29
  • are you using the latest 1.1.0-alpha10 ? – Gabriele Mariotti Oct 02 '19 at 11:34
  • @GabrieleMariotti yes, i'm using `implementation 'com.google.android.material:material:1.1.0-alpha10'` – Goku Oct 02 '19 at 11:35
  • Ok. I am checking the colors. For example in the header it is used:?attr/colorPrimary. It explain your white header. – Gabriele Mariotti Oct 02 '19 at 11:39
  • @GabrieleMariotti thank you for your response if possible please post an answer so it can help me to understand and help other also – Goku Oct 02 '19 at 11:41
  • Ok.Thanks for the feedback.I will add some info about the colors, just the time to check. The issue is there. – Gabriele Mariotti Oct 02 '19 at 11:44
  • @GabrieleMariotti thank you if possible please reopen the question – Goku Oct 02 '19 at 11:47
  • I've updated the linked answer with the (main) colors used in the material calendar. Check with the colors defined in your app theme. It should be enough without reopening the question. – Gabriele Mariotti Oct 02 '19 at 13:15

0 Answers0