Java 如何更改alertDialog中项目的字体?
我有带有项目的Java 如何更改alertDialog中项目的字体?,java,android,android-alertdialog,Java,Android,Android Alertdialog,我有带有项目的alertDialog 代码如下: final CharSequence[] options = { "Back","continue"}; AlertDialog.Builder builder = new AlertDialog.Builder(myActivity.this); builder.setTitle(customTitle); builder.setItems(opti
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使用的标题或文本,
我需要更改项目的字体,有人可以帮助我吗?要执行此操作,请使用警报生成器生成警报。然后从该警报中获取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);
我试过这种方法,但应用程序崩溃了,这种方法是改变字体的项目也?我需要在代码中的何处添加这些行?可能我没有将它们放在正确的行中?您必须在
onCreate
方法中添加代码。此外,您还需要在资产中添加字体文件。如果你的api是,看看这篇文章,如果你不能使它。祝你好运,这句话是什么意思?AlertDialog dialog=new AlertDialog.Builder(this).setMessage(“Hello world”).show();我需要把alertDialog放在哪里?链接是关于文本视图的,alertDialog项目呢?我不明白你的答案…我看了同样的问题,但没有找到我具体问题的答案,有人能帮我吗?