Android DatePicker Typeface

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz picture zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz · Feb 9, 2012 · Viewed 14.5k times · Source

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?

Answer

asannov picture asannov · Nov 2, 2012

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);
}