2014-10-03 45 views
0

最近完成了一個應用程序,並且被告知當用戶在他們的評論中添加表情符號時,它們會第一次顯示並消失。在android中處理表情

我一直在使用comment.setText(Html.fromHtml(text));

我從來沒有真正考慮表情顯示的意見,這是我的嘗試與一個應用程序來處理它們第一次。在textview中顯示笑臉的默認行爲是什麼?我檢查了我的默認鍵盤,並且沒有表情符號,因此用戶可能正在使用自定義鍵盤。停止處理自定義小鍵盤的輸入或處理應用程序中的笑臉通常是最好的方法。

回答

0

Android Span允許您根據需要格式化代碼。您可以使用ImageSpan呈現在TextView中輸入文本「:-)」的任何位圖:如果什麼笑臉從直接選擇 http://blog.stylingandroid.com/introduction-to-spans/

+1

String text = "here is a smiley :-)"; String smileyStr = ":-)"; SpannableString ss = new SpannableString("Here's a smiley :-)"); int smileyStart = text.indexOf(smileyStr); Bitmap smiley = BitmapFactory.decodeResource(getResources(), R.drawable.emoticon); ss.setSpan(new ImageSpan(smiley), text.indexOf(smileyStr), smileyStr.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); textView.setText(ss); 

你可以找到更多在這裏鍵盤?這是否也處理? – Amanni 2014-10-03 12:07:24