9.0 pie – Custom font in AnkiDroid in Android 9? (Kanji Stroke Order)

Short version

How to use custom font, namely Kanji Stroke Order, in cards in AnkiDroid which is running on Android 9?

Full version

I’m learning Kanji characters. It’s important to learn also how to draw them – the order of strokes. This is shown in Anki cards by using a special font – Kanji Stroke Orders – and simply printing the character in card with this font. However, I’m unable to make AnkiDroid to use the font, but it was working on my previous device (Android 5.1).

The deck describes that the font file should be copied to fonts sub-directory of AnkiDroid directory. And that it might be needed to remove version part of file name. So I copied the fonts to following paths:

  • /storage/emulated/0/AnkiDroid/fonts/KanjiStrokeOrders_v4.002.ttf
  • /storage/emulated/0/AnkiDroid/fonts/KanjiStrokeOrders.ttf

Doesn’t work (the character is drawn simply with Arial or something like that).

I found another way – Installing Fonts in Anki documentation. This guide describes following approach:

  • Add underscore to the font file name.
  • Copy it to “collection.media” sub-directory of “User 1” sub-directory of AnkiDroid directory. I couldn’t find the “User 1”, but there was “collection.media” in AnkiDroid directory, so I used that.
  • Add @font-face { font-family: myfont; src: url("_arial.ttf"); } to style section of a card and use font-family: myfont in style of the kanji text block.

So what I added to the style section is:

  font-family: KanjiStrokeOrders;
  src: url("_KanjiStrokeOrders.ttf");

Then I added to card text:

<span style="font-family:KanjiStrokeOrders;">{{Expression}}</style>

And copied the font files to:

  • /storage/emulated/0/AnkiDroid/collection.media/_KanjiStrokeOrders_v4.002.ttf
  • /storage/emulated/0/AnkiDroid/collection.media/_KanjiStrokeOrders.ttf

And just in case, I also created files:

  • /storage/emulated/0/AnkiDroid/fonts/_KanjiStrokeOrders_v4.002.ttf
  • /storage/emulated/0/AnkiDroid/fonts/_KanjiStrokeOrders.ttf
  • /storage/emulated/0/AnkiDroid/collection.media/KanjiStrokeOrders_v4.002.ttf
  • /storage/emulated/0/AnkiDroid/collection.media/KanjiStrokeOrders.ttf

Still doesn’t work, the text replacing {{Expression}} placeholder is still rendered in Arial (or similar).

Other notes

  • The /storage/emulated/0/AnkiDroid directory was already created and contains Anki data, similar to what is in ~/Anki/User 1 on my PC (Linux, Ubuntu).
  • I’m sure the cards/notes are correct (correct format, content, etc.), because it works on PC and worked on my older Android 5.1 phone (I used export/import to migrate and for backups). (I don’t rember where I put the font file in my previous phone; the device screen died and so I cannot check now.)
  • It seems that the AnkiDroid actually see the font; in settings / Appearance / Default font, there actually is option to select Kanji Stroke Orders (all four versions – with/without underscore and with/without version suffix). When I choose it (and set Default font applicability to Always), nothing change. But the font is also available under Browser and editor font – when I set this one to Kanji Stroke Orders, it will change questions and answers in Card browser and field values in note editor. So the font seems to be recognized by AnkiDroid and working.