在 API 中使用 XML 中的字体 <26 [英] Using font in XML in API < 26

查看:24
本文介绍了在 API 中使用 XML 中的字体 <26的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

https://developer.android.com/preview/features/使用字体.html

Android API 26 支持这一点,但是我们是否有一个支持库可以提供使用字体作为 res 中的资源?[XML 中的字体] 如果是,它支持哪些 API?

Android API 26 supports this but do we have a support library that can provide use of fonts as a resource in res? [ font in XML ] If yes, up-to what API is it supported?

我说的是 Android O SDK 功能,它允许我们在 XML 中设置字体,如上面的链接所示.我敢肯定,这不是 MM 的原生功能.

I am talking about the Android O SDK feature which allows us to set font in XML as given in the link above. This is not a native feature in MM I m sure.

推荐答案

据 Google 称,只要满足以下条件,它就支持 Android 4.0+ (API 14+):

According to Google it is supported on Android 4.0+ (API 14+) as long as these conditions are met:

  • 您使用的是支持库版本26.0.0-beta1或更高版本
  • 您正在使用 AppCompat
  • You are using the support library version 26.0.0-beta1 or later
  • You are using AppCompat

来源:

XML 中的字体 - 使用支持库

支持库修订历史

我希望我可以在早于 8 (API 26) 的 Android 版本上的应用小部件中使用它,但这是不可能的,因为 AppCompatTextView 不能在应用小部件中使用.Android O 的XML 中的字体"的第三方替代品(例如 Caligraphy 库)均不适用于应用小部件要么.

I was hoping I could use this in app widgets on Android versions earlier than 8 (API 26), however it's not possible, as AppCompatTextView cannot be used in app widgets. None of the third party alternatives to Android O's 'Fonts in XML' such as the Caligraphy library work in app widgets either.

应用小部件的唯一替代方法是使用 ImageView 而不是 TextView 并使用 RemoteViews 方法,例如 setImageViewUri(...)setImageViewBitmap(...),两者都有问题.

The only alternative for app widgets is using an ImageView instead of a TextView and using RemoteViews methods such as setImageViewUri(...) and setImageViewBitmap(...), both of which are problematic.

这篇关于在 API 中使用 XML 中的字体 <26的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆