I am aware you can apply a custom TypeFace to a TextView in Android like this:
TextView tv = findViewById(R.id.textview01);
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/BLACKROSE.TTF");
tv.setTypeface(tf);
Is there any way possible to do this for a DatePicker?
Here is my code. I hope it will be useful to someone.
DatePicker datePicker = (DatePicker) findViewById(R.id.datePicker1);
LinearLayout layout1 = (LinearLayout) datePicker.getChildAt(0);
LinearLayout layout = layout1.getChildAt(0);
// day
LinearLayout day = (LinearLayout) layout.getChildAt(0);
setNumberPicker(day);
// month
LinearLayout month = (LinearLayout) layout.getChildAt(1);
setNumberPicker(month);
// year
LinearLayout year = (LinearLayout) layout.getChildAt(2);
setNumberPicker(year);
...
private void setNumberPicker(LinearLayout ll) {
((ImageButton) ll.getChildAt(0)).setBackgroundResource(R.drawable.plus_button);
((ImageButton) ll.getChildAt(2)).setBackgroundResource(R.drawable.minus_button);
EditText et = (EditText) ll.getChildAt(1);
et.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
et.setTypeface(youtTypeface);
}
After taking a look at the source, the Datepicker widget holds 3 NumberPicker widgets (for day, month, year)which in turn hold a TextView. So you are going have to set the Typeface for the TextView inside the NumberPickers inside the DatePicker.
I think you'll have to get the source for both NumberPicker and DatePicker and modify the source to achieve this, easier said than done I'm afraid.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With