material-components / material-components-android

Modular and customizable Material Design UI components for Android
Apache License 2.0
16.42k stars 3.08k forks source link

[MaterialDatePicker] Allow disabling of manual entry of date #839

Closed anilgorthy closed 4 years ago

anilgorthy commented 4 years ago

When I switch to the manual entry of date using a keyboard, the error messages when entering an invalid date format are confusing to our users and it takes at least two attempts before they understand the preferred format

Either the field should auto-format with "/" after entering the digits or allow developers to provide a custom message.

I tried to find a way to disable (see the attached image) the manual entry so, that users cannot enter the date manually but the API doesn't provide any mechanism.

Allow_Developers_To_Disable_Manual_Entry

kuelye commented 4 years ago

@anilgorthy, you can use custom style as workaround to disable calendar input mode toggle. This toggle uses style attribute materialCalendarHeaderToggleButton, so:

<style name="Widget.AppTheme.MaterialDatePicker" parent="ThemeOverlay.MaterialComponents.MaterialCalendar">
    <item name="materialCalendarHeaderToggleButton">@style/Widget.AppTheme.MaterialCalendar.HeaderToggleButton</item>
</style>    

<style name="Widget.AppTheme.MaterialCalendar.HeaderToggleButton" parent="Widget.MaterialComponents.MaterialCalendar.HeaderToggleButton">
    <item name="android:visibility">gone</item>
</style>

And after that apply theme with:

MaterialDatePicker.Builder.dateRangePicker()
        .setTheme(R.style.Widget_AppTheme_MaterialDatePicker)
gabrielemariotti commented 4 years ago

Duplicate #1380