本文介绍了如何将语言环境(带有国家/地区)添加到字体资源(支持库v26)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自支持库v26发布以来,Google已发布了官方字体资源处理: https://developer.android.com /guide/topics/ui/look-and-feel/fonts-in-xml.html

Google published the official font resources handling since support library v26 released:https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml.html

但是,看起来我无法为字体资源文件夹添加国家/地区限定符.

However, looks like I cannot add country qualifier for the font resources folder.

我有一个具有3种语言的应用程序:英语,繁体中文和简体中文.

I have an app which has 3 languages: English, Traditional Chinese and Simplified Chinese.

然后我尝试用这种方式在res下命名我的字体文件夹:
font
font-zh
font-zh_CN
(我也尝试过font-zh-CN)

And I tried to name my font folder under res this way:
font
font-zh
font-zh_CN
(I have also tried font-zh-CN)

(请注意,zh是语言,而CN是国家.在您提供更多信息的情况下-在中国,我们都使用中文",但是有简体中文和繁体中文;此外,香港和台湾都使用繁体中文,但是我们使用它们的方式略有不同.最重要的是,字体具有繁体中文和简体中文的单独文件,这是因为它们的形状存在很大差异.)

(Note that zh is the language, while CN is the country. With some more context for your information - In China we all use "Chinese", but there are Simplified Chinese and Traditional Chinese; Moreover, Hong Kong and Taiwan both use Traditional Chinese but the way we use them are a bit different. Most importantly, typefaces have separate files for Traditional Chinese and Simplified Chinese, due to the fact that they are quite different in their shapes.)

但是我无法构建该项目. Android Studio不断告诉我font-zh_CN(或font-zh-CN)是无效的资源目录名称.

But I cannot build the project. Android Studio keeps telling me that font-zh_CN (or font-zh-CN) is an invalid resource directory name.

对于我的values-zh_CN文件夹(也不是values-zh-CN),这不会发生.

This does not happen for my values-zh_CN folder (nor values-zh-CN).

问题:

自API 26开始,您如何使用新的官方方法为同一语言但不同国家/地区使用不同的字体?

How do you use different fonts for the same language but different country, using the new official method since API 26?

推荐答案

表2中定义了资源文件夹名称的模式: https://developer.android.com/guide/topic/resources/providing-resources.html#Alternative%20Resources

The pattern for resource folder names is defined in Table 2 here:https://developer.android.com/guide/topics/resources/providing-resources.html#Alternative%20Resources

具体来说,尝试:

font-zh-rCN

这篇关于如何将语言环境(带有国家/地区)添加到字体资源(支持库v26)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 14:29