您应该设置布局的自定义视图,而不是设置alertdialog的文本。在执行此操作之前,请修改视图的字体。
TextView mycontent = (TextView) findViewById(R.id.yourid); mycontent.setTypeface(Typeface.createFromAsset(getAssets(), "font.ttf")
并设置警报对话框的视图,请致电
.setView(mycontent),
setMessage()尽管据我所知,这不会更改您的标题。
更新 我看到您无法理解我的意思,所以这是一个完整的示例
TextView content = new TextView(this); content.setText("on another font"); content.setTypeface(Typeface.SANS_SERIF);//Use the first example, if your using a xml generated view alertDialog.Builder myalert = new alertDialog.Builder(this); myalert.setTitle("Your title"); myalert.setView(content); myalert.setNeutralButton("Close dialog", null); myalert.setCancelable(true); myalert.show();这使用的是我们刚刚创建的TextView,并且没有边距等。如果使用易于创建的一种形式的布局文件,则可以自定义所有这些设置,尽管您可以在本示例中将其设置为代码形式。
当然,将字体替换为所需的字体。来自xml的示例TextView可能是:
<TextView android:id="@+id/yourid" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="8dp" android:text="your content" />



