在Android中的对话框中设置自定义字体(TypeFace)

obr*_*ien 6 android dialog typeface

我想在textview中更改对话框中的字体:

dialog = new Dialog(MyActivity.this);
dialog.setContentView(R.layout.my_dialog);
dialog.setCancelable(true);
((TextView)findViewById(R.id.dialog_box_title_text)).setTypeface(Typeface.createFromAsset(getAssets(), "font.ttf"));
Run Code Online (Sandbox Code Playgroud)

但每次我得到运行时异常:

E/AndroidRuntime(4475):java.lang.IllegalStateException:无法执行活动的方法

你知道什么是错的吗?因为通常它工作正常.只有在尝试更改对话框中的字体时才会出现问题.

use*_*305 17

试试这个,让我知道发生了什么.

((TextView)dialog.findViewById(R.id.dialog_box_title_text)).setTypeface(Typeface.createFromAsset(getAssets(), "font.ttf"));
Run Code Online (Sandbox Code Playgroud)