Search code examples
androidmaterial-components-androidandroid-datepicker

Change width and height of MaterialDatePicker in Android


Users of my app use 10", 15", and 22" android tablets. I'm employing the MaterialDatePicker control to allow them to choose dates in an activity. I'm getting complaints that the numbers in the calendar are too tiny and hard to hit in just the right way. I'd like to make the entire control 30% larger. I was able to set the theme upon creating the control:

            val builder = MaterialDatePicker.Builder.datePicker()
            builder.setTitleText(R.string.label_end_date)
            builder.setTheme(R.style.MaterialDatePickerStyle)

I was able to increase text size:

<style name="MaterialDatePickerStyle" parent="ThemeOverlay.MaterialComponents.MaterialCalendar">
    <item name="android:textSize">18sp</item>
</style>

android:Width has no effect, scaleX/scaleY aren't doing the job either.


Solution

  • You can't change android:textSize in this way since it is not an attribute theme.
    To change the dimension of the text used in the days you can use something like:

       <style name="MaterialDatePickerStyle" parent="ThemeOverlay.MaterialComponents.MaterialCalendar">
            <item name="materialCalendarDay">@style/Widget.App.MaterialCalendar.DayTextView</item>
        </style>
    
        <style name="Widget.App.MaterialCalendar.DayTextView" parent="Widget.MaterialComponents.MaterialCalendar.DayTextView">
            <item name="android:textAppearance">?attr/textAppearanceBody1</item>
        </style>
    

    enter image description here