android - 我可以在 Android 应用程序中嵌入自定义字体吗?

标签 android fonts

我想让一个应用程序包含一个用于呈现文本的自定义字体,加载它,然后将它与标准元素(如 StaticText)一起使用。这可能吗?

最佳答案

是的,你可以,你只是不能将它定义到 xml 布局中。您每次都需要动态使用它。查看 this tutorial例如。

如果链接失效,这里是一个总结:

  • 获取像 times.otf
  • 这样的字体文件
  • 将其放入您的 Assets 文件夹中的“字体”文件夹中
  • 使用类似的方式获取 TextView 的引用:

    TextView tv = (TextView) findViewById(R.id.myCustomTVFont);
    
  • 从资源文件夹中获取字体:

    Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/times.otf");
    
  • 让你的 TextView 看起来很棒:

    tv.setTypeface(tf);
    

关于android - 我可以在 Android 应用程序中嵌入自定义字体吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3424165/

相关文章:

android - JKS、BKS 和 PKCS12 文件格式

android - 如何更改android : layout_centerHorizontal = "true" to "false" at runtime

javascript - 如何在 HTML 中正确包含字体

html - 如果谷歌字体不可用,如何指定网络安全用户默认字体

css - 如何修复 font-stretch 属性以开始工作

android 向特定联系人发送 Intent (whatsapp、短信、远足等)

android - 将 InputStream 与 MultipartEntityBuilder 一起使用 : apache error

css - @font-face 规则 microsoft edge fonts.com 没有可用的字体

user-interface - 用户界面字体和语言

Android:将图像上传到 Facebook 上的特定相册