android – 检查自定义字体是否可以显示字符
作者:互联网
我有一个显示框字符的自定义字体.我使用的字体显然不支持所有语言.我想检查我要显示的字符串是否可以通过我的自定义字体显示.如果它不能,那么我想使用标准的Android字体(我知道可以显示字符).我找不到一种方法来检查我的Typeface是否可以显示特定的字符串.我相信我已经看到了一种方法可以解决这个问题.谁知道?
解决方法:
从Android版本23开始,您可以像这样测试它:
Typeface typeface;
//initialize the custom font here
//enter the character to test
String charToTest="\u0978";
Paint paint=new Paint();
paint.setTypeface(typeface);
boolean hasGlyph=paint.hasGlyph(charToTest);
标签:custom-font,android,typeface 来源: https://codeday.me/bug/20190927/1824823.html