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

标签 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"));

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

E/AndroidRuntime(4475): java.lang.IllegalStateException: Could not execute method of the activity

你知道哪里出了问题吗?因为通常它工作正常。只有在尝试更改对话框中的字体时才会出现问题。

最佳答案

试试这个,让我知道会发生什么。

((TextView)dialog.findViewById(R.id.dialog_box_title_text)).setTypeface(Typeface.createFromAsset(getAssets(), "font.ttf"));

关于android - 在 Android 对话框中设置自定义字体 (TypeFace),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8211198/

相关文章:

android - 我可以省略对话框标题吗?

android - 扩展 BaseAdapter 类中的字体错误

android - 如何使用 InputStream 加载字体

android - android中上下文菜单项的字体

android - 如何在Android 7.1上设置最大声音

jquery - 为什么 jQuery UI 1.10 删除了 jquery 对话框 zIndex 选项?

android - 移动设备(Android、iOS、Windows Phone)上的 TensorFlow

java - 从 DialogFragment 调用 FileProvider 时出错 - 引用对象为空,

android - 为什么 React-Native 无法在与 Expo 的 Android 连接上启动项目?

java - Base64 编码器和解码器