1

I have set

<item name="android:textSize">12sp</item>

in the style of the app [AppTheme].

As a consequence, the year label and the summary label in the date picker dialog has gone smaller. I am trying to edit the sizes of them.

enter image description here

I tried various solutions from StackOverflow. But, none of them worked for me. Instead, the calendar is covering the whole screen. Kindly help me with this issue.

Sethuraman Srinivasan
  • 1,528
  • 1
  • 20
  • 34

2 Answers2

1

You can use a custom theme for your date picker like this

  <style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorAccent">@color/colorPrimary</item>
    <item name="android:textSize">25sp</item>
</style>


and your date picker dialog like this

 new DatePickerDialog(MapActivity.this, R.style.DialogTheme, new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                    //DO SOMETHING
                }
            }, 2019, 11, 25).show();
Sandeep dhiman
  • 1,863
  • 2
  • 17
  • 22
1

In the datetime picker there are three things you can control. The year text in the header, the date which is below the year. And last is the buttons (Cancel and okay).

To change the buttons size and font just edit your something like:

<style name="datepicker_dialog" parent="Theme.AppCompat.Light.Dialog">
    <item name="android:colorAccent">@color/black_000</item>
    <item name="android:colorControlActivated">@color/black</item>
    <item name="android:textSize">14sp</item>
    <item name="fontFamily">@font/yourFont</item>
    <item name="android:textAllCaps">false</item>
</style>

To change the year and date font and size you have to jump into the code where you define the DatePickerDialog:

val dialog = DatePickerDialog(activity, this,
                    params[0],
                    params[1],
                    params[2])
val baseLayout = dialog.datePicker.getChildAt(0) as LinearLayout
val childLayout = baseLayout.getChildAt(0) as LinearLayout

val titleLayout = childLayout.getChildAt(0) as LinearLayout

val dayText = titleLayout.getChildAt(1) as TextView
dayText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20f)
dayText.typeface = ResourcesCompat.getFont(activity, R.font.yourFont)

val yearText = titleLayout.getChildAt(0) as TextView
yearText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12f)
yearText.typeface = ResourcesCompat.getFont(activity, R.font.yourFont)

dialog.show()
Muhammad Faizan
  • 156
  • 1
  • 6