<分区>
我想在我的 android 应用程序的所有 View 中使用 Roboto 字体,我该怎么做?
标签 android
<分区>
我想在我的 android 应用程序的所有 View 中使用 Roboto 字体,我该怎么做?
最佳答案
创建自定义 View ,如 TextView、EditText 等。然后在构造函数中设置下面的 setTypeface 示例:
public class RobotoTextView extends TextView {
public RobotoTextView(Context context) {
super(context);
setTypeface(Typeface
.createFromAsset(context.getAssets(), "fontname.ttf"));
}
}
然后只需在您的布局中使用它,而不是使用标准的 TextView,使用下面的自定义类示例:
<packagename.RobotoTextView
style="@style/usecustomstyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/yourid"/>
关于android - 如何在我的 Android 应用程序中为所有 View 使用 Roboto 字体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14650111/
相关文章:
java - cursor.getCount() 返回 1 但应该返回 0
java - 使用 jcodec SequenceEncoder
android - 使用 Httpsurlconnection 连接到服务器 (SSL)
android - 如何将 byte[] 转换为 String 而不会在 Android 中出现内存不足错误?
android - CSS:适用于各种移动设备的字体大小、物理按钮高度
javascript - Appium Node 示例测试未运行
android - 如何修复 Android Studio 中的 NDK 构建错误
android - 智能手机(Android、iOS 等)上的 DRM
android - support.v7.app.AlertDialog 在关闭时抛出 NullPointerException