java - 如何更改 Android DatePickerDialog 中的字体

标签 java android fonts datepicker

我想更改 DatePickerDialog 中的字体,但我不知道如何设置

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

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

最佳答案

试试这个

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

关于java - 如何更改 Android DatePickerDialog 中的字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45977184/

相关文章:

java - ListView 上的弹出上下文菜单保持

java - java登录后返回全名

android - 每次我用 gradle 构建项目时自动运行 GreenDao 生成器

java - KSOAP 元素的排序

java - `@Autowire` 正在工作,即使 <context :annotation-config/>, 没有注释替换

java - 如何将文件中的数字列表放入数组并返回数组

android - 如何显示位图资源与使用形状绘制命令?

html - Hot to Code Custom Font in HTML/CSS 以在其他计算机上正确显示

CSS font-face 不起作用

python - 使用开放式字体和 pdf 导出在 Matplotlib 中进行字体缩放