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

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

问题描述

https://developer.android.com/preview/features/ working-with-fonts.html



Android API 26支持这个功能,但是我们有一个支持库,可以提供字体作为资源的使用。 [XML中的字体]如果是的话,支持什么API?

我正在谈论Android O SDK功能,它允许我们按照上面的链接给出的XML设置字体。当然,这不是MM的原生功能。根据Google的说法,只要支持 Android 4.0+(API 14 +),就可以支持 这些条件得到满足:


  • 您正在使用支持库版本 26.0.0-beta1 或更高版本
  • 您正在使用 AppCompat



来源:

XML中的字体 - 使用支持库

支持库修订记录



我可以在早于8(API 26)的Android版本的应用程序窗口小部件中使用它,但是这是不可能的,因为AppCompatTextView不能在应用程序窗口小部件中使用。 Android O的XML中的字体(如书法库)的第三方替代品在应用程序窗口小部件中都不起作用



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


https://developer.android.com/preview/features/working-with-fonts.html

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?

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.

解决方案

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

  • You are using the support library version 26.0.0-beta1 or later
  • You are using AppCompat

Sources:

Fonts in XML - Using the support library

Support Library revision history

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.

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天全站免登陆