How to change textsize in datepicker?

19,917

Solution 1

Setting a theme to DatePicker layout and adding android:textSize to it works for me.

In your layout's xml add a DatePicker applying a theme as shown below -

<DatePicker xmlns:android="http://schemas.android.com/apk/res/android"
            android:theme="@style/NumberPickerStyle"
            android:datePickerMode="spinner"
            android:calendarViewShown="false"
            android:layout_gravity="center_horizontal"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"/>

and then define the NumberPickerStyle in styles.xml specifying android:textSize like this -

<style name="NumberPickerStyle">
        <item name="android:textSize">@dimen/number_picker_text_size</item>
</style>

Solution 2

The easiest way to change the font size of datepicker/timepicker/numberpicker is customizing the theme.

In styles file, set the default font size in the following way.

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="android:textSize">22sp</item>
</style> 

Solution 3

Sean's approach made some glitches in the UI of picker itself in case there're a number of pickers and I think it's not perfect to apply text size to all the components under the picker. Below is what I've used and it works perfect without any UI glitches.

<style name="PickerTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:editTextStyle">@style/PickerEditText</item>
</style>

<style name="PickerEditText" parent="ThemeOverlay.AppCompat.Dark">
    <item name="android:textSize">24sp</item>
</style>
Share:
19,917
gcl1
Author by

gcl1

Developer in Boston area

Updated on June 04, 2022

Comments

  • gcl1
    gcl1 about 2 years

    The default textsize in datepicker is too big for my app. I've seen a way suggested to change it here, but fishing around for the textviews nested inside the datepicker class seems clunky and error prone.

    Is there a better/cleaner way to do it?