如何在DatePickerDialog android中更改字体

时间:2017-08-31 08:49:37

标签: java android fonts datepicker

我想在DatePickerDialog中更改字体,但我不知道设置它

如何更改DatePickerDialog android中的字体? 谢谢!

DatePickerDialog datePickerDialog = new DatePickerDialog(
    getContext(), this, startYear, starthMonth, startDay);

1 个答案:

答案 0 :(得分:0)

试试这个

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

这也是

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

现在使用此方法更改类型

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