gpt4 book ai didi

android - 检测是否支持 unicode 字符?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:19:25 26 4
gpt4 key购买 nike

我正在尝试组装一个可以随机向用户返回表情符号的小型 Android 应用程序。我的 Intent 是只使用实际的 unicode 表情符号字符,并将它们作为 unicode 字符串字符返回。

我构建了一个完整的 unicode 字符串数组,可以从中随机选择,而且很多都可以正确显示。然而,有些显示为不受支持的字符(一个带有 x 的矩形)。

显然不是每个平台都支持每个 unicode 表情符号字符,但如果可能的话,我想要一种方法来确定什么是受支持的字符,什么不是受支持的字符。理想的情况是查询支持的字符列表,但能够测试单个字符也能很好地完成这项工作。

最佳答案

另请查看 API 级别 23 中添加的 Paint.hasGlyph(String)。您可以使用它来测试表情符号等字符是否有可用的字形。

这就是documentation说:

boolean hasGlyph (String string)

Determine whether the typeface set on the paint has a glyph supportingthe string. The simplest case is when the string contains a singlecharacter, in which this method determines whether the font has thecharacter. In the case of multiple characters, the method returns trueif there is a single glyph representing the ligature. For example, ifthe input is a pair of regional indicator symbols, determine whetherthere is an emoji flag for the pair.

Finally, if the string contains a variation selector, the method onlyreturns true if the fonts contains a glyph specific to that variation.

Checking is done on the entire fallback chain, not just the immediatefont referenced.

另见

关于android - 检测是否支持 unicode 字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38162812/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com