如何更改alertDialog中的项目字体?

时间:2016-02-11 11:30:47

标签: java android alertdialog

我有alertDialog项目,

这是代码:

  final CharSequence[] options = { "Back","continue"};
              AlertDialog.Builder builder = new  AlertDialog.Builder(myActivity.this);
              builder.setTitle(customTitle);

                builder.setItems(options, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int item) {
                        if (options[item].equals("Back"))
                        {

                            //do something;


                        }
                        else if (options[item].equals("continue"))
                        {
                           dialog.dismiss();
                        }

                    }
                });
                builder.show();

我的资源文件夹中有自定义字体,如何将项目字体连接到此字体? 我看到了很多答案,但是对话框中的itmes没有答案,所有答案都是关于textView使用的标题或文本, 我需要更改我的项目的字体,有人可以帮助我吗?

1 个答案:

答案 0 :(得分:-2)

要执行此操作,请使用警报构建器来构建警报。然后,您可以从此警报中获取TextView,然后设置警报的字体。

AlertDialog dialog = new AlertDialog.Builder(this).setMessage("Hello world").show();
TextView textView = (TextView) dialog.findViewById(android.R.id.message);
Typeface face=Typeface.createFromAsset(getAssets(),"fonts/yourfont.ttf"); 
textView.setTypeface(face);