Displaying emoticons in 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 中显示表情符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Android 中显示表情符号


- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01