Reputation: 55
I want to change the font of time as below to 42sp. Is TimePickerDialog
possible to change the font size?
Upvotes: 0
Views: 1006
Reputation: 121
By default time picker has its own style but if you define other custom textview Style, then header of timepicker will be affected.so To Resolve this, you have to give custom style as follow
open your style or theme.xml file
inside style tag add following item
<item name="android:timePickerDialogTheme">@style/customTimePickerDialogTheme</item>
then add the following style outside the default style tag (inside resources)
<style name="customTimePickerDialogTheme" parent="@style/Theme.AppCompat.Light.Dialog">
<item name="android:headerBackground">#ff80cbc4</item>
</style>
By this way we achieve our default custom timepicker design.Now you can change font, texsize,color using other attribute inside customTimePickerDialogTheme.
Upvotes: 0
Reputation: 1606
I had a similar kind of issues you were facing. I finally used this GitHub library to customise the text sizes. Issue 1 and Issue 2 of that library could point you on how to increase text sizes. The code is in Java
Upvotes: 0
Reputation: 62209
TimePickerDialog
is not designed in a way, that would allow clients to change the font size. Thus, it's strongly discouraged to do so.
Still, if for some specific reason you need to do so, you are able to stick with following tricky and non-reliable way:
val mTimePickerField = TimePickerDialog::class.java.getDeclaredField("mTimePicker")
mTimePickerField.isAccessible = true
val mTimePicker = mTimePickerField.get(timePickerDialog) as TimePicker
val hours: TextView? = mTimePicker.findViewById(resources.getIdentifier("android:id/hours", "id", packageName))
val separator: TextView? = mTimePicker.findViewById(resources.getIdentifier("android:id/separator", "id", packageName))
val minutes: TextView? = mTimePicker.findViewById(resources.getIdentifier("android:id/minutes", "id", packageName))
hours?.textSize = 12f
separator?.textSize = 12f
minutes?.textSize = 12f
Here's what you'll get:
time_picker_header_material.xml
is the actual header layout that TimePickerDialog
will inflate, thus you can enhance am/pm fields as per your needs with the same approach as it's done for hours/separator/minute.
Upvotes: 1