Android:如何更改 AlertDialog 消息和按钮的字体系列

标签 android android-alertdialog android-fonts

我在单击按钮时显示一个 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/

相关文章:

java - ListView 返回相同的项目位置和 ID

android - 使用客户经理获取 OAuth token

android - DatePicker 将日期格式化为系统区域设置

android - 可下载字体异常(exception)

android - 105 字符十六进制的 Google Play 商店应用签名 key 问题

android - 在 fragment 中的自定义构建对话框中使用 Android GraphView

android - 警报对话框上带有多选复选框的列表?

android - 基于 String 内部语言的 TextView 自定义字体

android - 为整个 Activity 设置字体设置

android - 不显示警报对话框