【发布时间】:2016-06-17 19:02:44
【问题描述】:
我正在开发一个正在实现表情符号的聊天应用程序,但我在适配器中有一个问题,如何在 Textview 中呈现表情符号。
emocationGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
emoDrawables.get(position).setBounds(0, 0, emoDrawables.get(position).getIntrinsicWidth(),
emoDrawables.get(position).getIntrinsicHeight());
int selectionCursor = chatMsgEtd.getSelectionStart();
chatMsgEtd.getText().insert(selectionCursor, ".");
selectionCursor = chatMsgEtd.getSelectionStart();
SpannableStringBuilder builder = new SpannableStringBuilder(chatMsgEtd.getText());
builder.setSpan(new ImageSpan(emoDrawables.get(position)), selectionCursor - ".".length(),
selectionCursor, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
chatMsgEtd.setText(builder);
chatMsgEtd.setSelection(selectionCursor);
}
});
适配器
chatMsgTxt.setText(chats.get(position).getMessage());
所以在适配器中 getMessage 是聊天消息,但这里如何用消息呈现表情符号。
请浏览我的帖子并建议我一些解决方案。
【问题讨论】:
-
你的表情是自定义的还是安卓默认的?
-
感谢您的回复,是的表情符号是我的自定义实现没有android默认的。
-
@cricket_007 emoji 是否有任何 unicode 值。
-
抱歉,应该将此标记为重复帖子。我刚刚选了一个得票最多的。 stackoverflow.com/questions/26893796/…