Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add locale(with country) to font resources (Support Library v26)?

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.

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

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)

(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.)

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.

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

Question:

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

like image 991
Sira Lam Avatar asked Nov 02 '17 02:11

Sira Lam


1 Answers

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

Specifically, try:

font-zh-rCN

like image 194
Sean Barbeau Avatar answered Sep 17 '22 20:09

Sean Barbeau