Material-components-android: [MaterialDatePicker] Allow disabling of manual entry of date

Created on 18 Dec 2019  路  2Comments  路  Source: material-components/material-components-android

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

feature request

Most helpful comment

@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)

All 2 comments

@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)

Duplicate #1380

Was this page helpful?
0 / 5 - 0 ratings