Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android DatePicker Typeface

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?

like image 543
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz Avatar asked Feb 09 '12 21:02

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz


2 Answers

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);
}
like image 189
asannov Avatar answered Sep 27 '22 16:09

asannov


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.

like image 28
triggs Avatar answered Sep 27 '22 18:09

triggs