Display emoji/emotion icon in Android TextView

后端 未结 4 1638
暖寄归人
暖寄归人 2020-12-05 05:32

I have some problem with displaying emoji icon in Android TextView

First, I found a list of emoji icon in unicode at here: http://www.easyapns.com/category/just-for-

4条回答
  •  长情又很酷
    2020-12-05 06:13

    It works fine if you convert the string to a char array and check each char, such as:

    StringBuilder sb = new StringBuilder();
    for (char curr : str.toCharArray()) {
        sb.append((SUPPORTED_EMOJI_SET.contains(curr)) ? convertCharToImgTag(curr) : curr);
    }
    

    where SUPPORTED_EMOJI_SET is just a set of chars, for example:

    new HashSet() {{
        add('\ue415');
        add('\ue056');
        ...
    }}
    

    You could also do this with a regex but I believe the above would run faster.

提交回复
热议问题