我在单击按钮时显示一个 AlertDialog,它将具有正负按钮,它们是带消息的 AlertDialog 的默认按钮。
我想更改那些按钮和消息的字体系列,我该如何更改?
下面是我的代码:
AlertDialog.Builder altDialog = new AlertDialog.Builder(context);
altDialog.setMessage(Constants.WARNING_STEPS);
altDialog.setTitle(Constants.WARNING);
altDialog.setCancelable(true);
altDialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
});
altDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
altDialog.show();
最佳答案
这里的重点是android.R.id文件中textviews和buttons的地址,分别是android.R.id.button1 and android.R.id.button2 and android.R.id.button3 还有android .R.id.消息
AlertDialog dialog = new AlertDialog.Builder(MainActivity.this)
.setMessage("آیا مایل به خروج از حساب کاربری هستید؟")
.setCancelable(true)
.setPositiveButton("بله", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
...
}
})
.setNegativeButton("خیر", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
...
}
}).show();
TextView textView = (TextView) dialog.findViewById(android.R.id.message);
textView.setTypeface(FontHelper.getIranSansTypeface(MainActivity.this));
Button btn1 = (Button) dialog.findViewById(android.R.id.button1);
btn1.setTypeface(FontHelper.getIranSansTypeface(MainActivity.this));
Button btn2 = (Button) dialog.findViewById(android.R.id.button2);
btn2.setTypeface(FontHelper.getIranSansTypeface(MainActivity.this));
关于Android:如何更改 AlertDialog 消息和按钮的字体系列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29911967/