Reputation: 8036
I created an Android app that includes custom fonts (i.e., Google Fonts). I include these by adding them to the APK at build time. However, I would like to allow users to supply their own TTF files at run-time in order to add greater flexibility to my app. Is this possible? If so, how do I do it?
Upvotes: 0
Views: 46
Reputation: 1007474
If your text is being rendered by Java code, use Typeface.createFromFile()
instead of whatever you are presently using (e.g., Typeface.createFromAsset()
). This only works with files on the filesystem that you can reach. If you have a Uri
to the font (e.g., from ACTION_OPEN_DOCUMENT
), you will need to make a local copy of the font file (e.g., on internal storage).
If your text is being rendered by WebView
, you should be able to add CSS rules that point to a font located on the filesystem, though I have not tried this. It's even possible that CSS could use a content://
Uri
like you get from ACTION_OPEN_DOCUMENT
, though I am skeptical that this will work.
Upvotes: 1