How to change textsize in datepicker?

gcl1 picture gcl1 · Jul 30, 2012 · Viewed 17.9k times · Source

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?

Answer

shubham1g5 picture shubham1g5 · May 7, 2018

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>