Is there a way to set a fallback typeface for views? My client is requesting a certain typeface to be used which does not support Cyrillic characters (and they want cyrillic languages..) so therefore any cyrillic characters are beautiful squares! I can't seem to find anything to set a fallback font for a textview?
In iOS theres a default fallback.. Don't let me down Android! The thought of remaking a textview and then changing every single one in my app to the new textview, to support a fallback makes my head hurt.
Thanks,
Currently you can't specify more than one typeface for a view's style declaration.
I guess you'll have to be applying some damage control right now, so you may get off by specifying two styles, one that will support the client's typeface and another that will be used to render user input. You can apply one of the two to the whole application and manually set the other style to override the default typeface.
Related
is there anyway to set custom font as a fallback font to the default font?
I need to display some cjk characters not supported by android's default font (which I think is noto font for non latin characters). I have a custom font consists of the glyphs missing, so I'm thinking to use noto as the main font, and set my custom font as fallback.
The only way I can come up with is to make noto font as a typeface and set my custom font as fallback. Then I can assign this typeface to where I need it.
However, this mean I need to programmatically assign almost all textview in the app, which doesn't seem right... (and elegant😅)
I would like to ask what is the best practice for this scenario? Like, perhaps there's a way to declare them as a font family in XML?
Thanks a lot ;)
Let me answer myself :)
After trying, I think the easiest way is to merge two font files together.
Just make sure the font's license allows you to do so.
I'm creating a custom View class that displays text using a StaticLayout with a custom typeface loaded from a .ttf asset file. The basic look of the typeface is a serif font and the TrueType properties in the font file indicate that it's serif. Nevertheless, for characters not in the font, Android falls back to a sans-serif typeface (it looks like Roboto or Noto, depending on the Android version).
Is there a way to control this so that the Android layout engine falls back to a serif typeface? (Like maybe some magic string to pass to Paint#setFontFeatureSettings(), or perhaps a way to specify a stack of typefaces for use in a Paint?)
Any solution would have to work when the app is distributed, so playing games with Android's system configuration files is not an option. Also, I'm aware of this question (that is still unanswered after four years), but my problem is a bit different, although the solution to both issues might very well be the same.
As of Lollipop, there's a hidden class called FontFamily and a hidden method called Typeface.createFromFamilies. If you're very careful, you can probably use this stuff via reflection or other trickery, but be prepared to fallback to the public API.
my problem is that I can't put '\u221c' unicode on button in Android app. '\u221a' is OK and works, but 221b and 221c doesn't. Also, when I want that button to put text '\u221c' in EditText it puts \u221a. I dont know why it works that way and how to fix this. Please help
This appears to be simply a font problem. U+221A SQUARE ROOT “√” is a much more common character in fonts than U+221B CUBE ROOT “∛” and U+221C FOURTH ROOT “∜”. You may need to find a font that contains them and bundle it into the application, or use other notations.
You can, in particular, use fractional powers instead of roots. That’s even the preferred way, according to the standard ISO 80000-2. So instead of ∜a, you would use “a” followed by “1/4” in superscript style, if that’s possible in the application.
Is it possible to set a custom font as default in a android application? Because typing this for every TextView is not efficient.
login = (TextView)findViewById(R.id.tvLogin);
login.setTypeface(titleFont);
Is it possible to set a custom font as default in a android application?
Not for a custom Typeface that you loaded from your own font file, sorry. As others have noted, there are workarounds and libraries to help simplify matters a bit. Personally, I'd look at Calligraphy or perhaps Fontify.
I am following an example project "Sky" by Jeff Sharkey using styles in my layout. It is working out quite well, however, I cannot determine how to specify the font type-face using the styles. Without this, I will have to apply the font explicitly to every TextView, EditView, etc., whereas I want to control where and when it is applied throughout my application.
It seems that it is not possible from xml/styles... You can only specify it from java code.
check here if you are interesting.
You can do this by creating your own textview class and use that in your layouts.
Inside your new custom class, set the font you want.
Et voila!