简体   繁体   English

如何从android中的字符串中提取文本笑脸

[英]How to extract text smileys from a string in android

I am working on an android application in which I want to convert all keyboard types smileys into emoji icons.我正在开发一个 android 应用程序,我想在其中将所有键盘类型的笑脸转换为表情符号图标。

I am already using this library https://github.com/ankushsachdeva/emojicon to show Emoticons in my app.我已经在使用这个库https://github.com/ankushsachdeva/emojicon在我的应用程序中显示表情符号。

Now, I want to convert the smileys which users will type using keyboard into emoticons.现在,我想将用户将使用键盘键入的笑脸转换为表情符号。

Ex: If user type the string Hello World :) :P: 1. Then I need to first extract these smiley symbols and for that I need a regex pattern which will extract all these types of symbols from a string.例如:如果用户输入字符串 Hello World :) :P: 1. 然后我需要首先提取这些笑脸符号,为此我需要一个正则表达式模式,它将从字符串中提取所有这些类型的符号。 2. I need to find Unicode of these symbols and then convert these symbols in emoticons using the above library. 2.我需要找到这些符号的Unicode,然后使用上面的库将这些符号转换为表情符号。

Please help me, so that I can proceed here.请帮助我,以便我可以继续这里。

this lib is using ImageSpan s and SpannableStringBuilder like here: EmojiconTextView这个库使用ImageSpan s 和SpannableStringBuilder就像这里: EmojiconTextView

public void setText(CharSequence text, BufferType type) {
    SpannableStringBuilder builder = new SpannableStringBuilder(text);
    EmojiconHandler.addEmojis(getContext(), builder, mEmojiconSize, mTextStart, mTextLength);
    super.setText(builder, type);
}

you can always remove spans from current SpannableStringBuilder and get plain text您始终可以从当前的SpannableStringBuilder删除跨度并获取纯文本

if you want to set spans "in fly" just use TextWatcher for your EditText , smth like here: EmojiconEditText如果你想在“飞行”中设置跨度,只需将TextWatcher用于你的EditText ,就像这里一样: EmojiconEditText

protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
    EmojiconHandler.addEmojis(getContext(), getText(), mEmojiconSize);
}

this lib seems to do all work for you, just use View s from lib ( Emojicon prefix) instead usual ones, eg这个库似乎可以为您完成所有工作,只需使用库中的ViewEmojicon前缀)而不是通常的,例如

<ankushsachdeva.emojicon.EmojiconTextView
        android:id="@+id/emojicon"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        emojicon:emojiconSize="24dip"
        android:gravity="center"/>

instead EditText in XML layout files而是 XML 布局文件中的EditText

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM