在strings.xml中定义一个标题字符串,并使用android:textSize属性设置标题的大小,例如:
在Java代码中,在创建AlertDialog的Builder对象之后,使用setTitle()方法将标题设置为上面定义的字符串,并使用setCustomTitle()方法将一个TextView设置为自定义的标题。在TextView上应该设置相同的android:textSize属性,例如:
AlertDialog.Builder builder = new AlertDialog.Builder(this); String title = getString(R.string.my_alert_dialog_title); TextView customTitle = new TextView(this); customTitle.setText(title); customTitle.setTextSize(getResources().getDimension(R.dimen.alert_dialog_title_size)); builder.setCustomTitle(customTitle); // 添加对话框的其他按钮等配置 builder.create().show();
在dimen.xml中定义(alert_dialog_title_size是一个自定义名称):
根据需要修改标题的大小。