在 Android 中显示表情符号

Displaying emoticons in Android(在 Android 中显示表情符号)
本文介绍了在 Android 中显示表情符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 IM 应用程序必须支持表情符号.它们是 GIF 并具有文本表示,如果用户选择其中之一,则会在输入框中使用.但我想在它们发送后将它们显示为图像.目前我的自定义数组适配器在一行的 TextView 中显示发送的消息.

My IM app has to support emoticons. They are GIFs and have textual representations, which are used in the input box if the user selects one of them. But I'd like to display them as images after they have been sent.Currently my custom array adapter displays the sent message in a TextView of a row.

根据文本表示的出现动态显示图像的正确方法是什么?我是否必须搜索表情符号文本,如果找到,请从布局中删除 TextView(relativeLayout 最适合?)并添加一个带有 IM 开头的 TextView、一个带有表情符号的 ImageView 和另一个 TextView.如果同时发送更多表情符号可能会很混乱.

What is the proper method to display images dynamically based on the occurrence of their textual representation? Do I have to search for emoticon texts, and if one found, remove the TextView from the layout (relativeLayout fits most?) and add a TextView with the beginning of the IM, an ImageView with the emoticon and another TextView. If more emoticons sent simultaneously it can be messy.

有没有更简单更合乎逻辑的方法?

Is there an easier and more logical way?

推荐答案

我会尝试使用正则表达式将每个表情符号的所有出现替换为 <img> 标记.然后,将该 HTML 转换为 SpannedString 通过 Html.fromHtml().SpannedString 可以在 TextView 上的 setText() 调用中使用.

I would try using a regular expression to replace all occurrences of each emoticon with an <img> tag. Then, convert that HTML into a SpannedString via Html.fromHtml(). That SpannedString can be used in a setText() call on TextView.

这篇关于在 Android 中显示表情符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)