How to change text in datepicker?

The default text texts in datepicker are too large for my application. I have seen the method proposed to change it here , but fishing around text views nested inside the datepicker class seems awkward and error prone.

Is there a better / clean way to do this?

+7
source share
7 answers

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

In the stylesheet, set the default font size as follows.

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

use below code:

 ViewGroup childpicker = (ViewGroup)datePicker.findViewById(Resources.getSystem().getIdentifier("month", "id", "android")); EditText mornthEt = (EditText)childpicker.getChildAt(1);// month widget //change textsize and textcolor for mornthEt mornthEt.setTextSize(30); mornthEt.setTextColor(Color.GREEN); 
+1
source

Sean's approach made some malfunctions in the collector's user interface, if there are several collectors, and I think that it is not ideal for applying text to all components under the collector. Below is what I used, and it works great without any UI crashes.

 <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> 
+1
source

Installing a theme in a DatePicker layout and adding android:textSize for it works for me.

In your xml layout add a DatePicker applying the theme as 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 indicating android:textSize like this -

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

use below code

  DatePicker picker = (DatePicker)findViewById(R.id.dp_date); ViewGroup childpicker = (ViewGroup) findViewById(Resources.getSystem().getIdentifier("month" /*rest is: day, year*/, "id", "android")); EditText textview = (EditText) picker.findViewById(Resources.getSystem().getIdentifier("timepicker_input", "id", "android")); textview.setTextSize(30); textview.setTextColor(Color.GREEN); 
0
source

I used the following CustomDateAndTimePicker . It is very easy to set up. The fact that different options, such as date, month, year, hours and minutes, have their own set of numbers. Thus, you can adjust the text size, color and other styles. you can add your own dialing for your use

0
source

Sean code works. but it also changes the font size for all other components (text elements, buttons, etc.). So here is the solution.

Create a different style for timing and use it on the theme of timing.

 <style name="my_time_picker_style"> <item name="android:textSize">24sp</item> </style> 

and use it on your timepicker

 android:theme="@style/my_time_picker_style" 

Watch the video how I did https://youtu.be/JMJ2ujhk9c0

0
source

All Articles