2

I want to change font in DatePickerDialog ,but I have no idea to set it

How to change font in DatePickerDialog android? thanks!

DatePickerDialog datePickerDialog = new DatePickerDialog(
    getContext(), this, startYear, starthMonth, startDay);
ARR.s
  • 769
  • 4
  • 20
  • 39

1 Answers1

0

try this

TextView titleTextView = (TextView) datePickerDialog.findViewById(android.R.id.title);
titleTextView.setText("Nilesh Rathod");
titleTextView.setTextSize(20);
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/BLACKROSE.TTF");
titleTextView.setTypeface(tf);
datePickerDialog.show();

and this also

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

now change type using this method

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);
    Typeface tf = Typeface.createFromAsset(getAssets(),   "fonts/BLACKROSE.TTF");
    et.setTypeface(tf);
}
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
  • in line `LinearLayout layout1 = (LinearLayout) datePicker.getChildAt(0);` cannot call `getChildAt(0)` – ARR.s Aug 31 '17 at 09:11
  • @ARR.s just add this DatePickerDialog in your xml layout – AskNilesh Aug 31 '17 at 09:15
  • @ARR.s **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.** – AskNilesh Aug 31 '17 at 09:16