评论页面表情处理(emoji)

Posted wangyaqian1212

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了评论页面表情处理(emoji)相关的知识,希望对你有一定的参考价值。

在studio中导入依赖

compile'com.tb.emoji:yykEmoji:1.0.0'

在xml布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/Container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ></FrameLayout>

    <TextView
        android:id="@+id/textview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/Container"
        android:layout_marginTop="20dp"
        android:textColor="#383838"
        android:textSize="16sp"
        />

    <EditText
        android:id="@+id/edit_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textview"
        android:layout_marginTop="20dp"
        android:textColor="#383838"
        android:textSize="16sp"/>
    <Button
        android:id="@+id/btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/edit_text"
        android:layout_marginTop="20dp"
        android:text="发送"
        />

</RelativeLayout>


在mainactivty中

public class MainActivity extends AppCompatActivity implements FaceFragment.OnEmojiClickListener
    TextView textView;
    EditText editText;
    private Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) 
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textView = (TextView) findViewById(R.id.textview);
        editText = (EditText) findViewById(R.id.edit_text);
        btn = (Button) findViewById(R.id.btn);
        FaceFragment faceFragment = FaceFragment.Instance();
        getSupportFragmentManager().beginTransaction().add(R.id.Container,faceFragment).commit();
        btn.setOnClickListener(new View.OnClickListener() 
            @Override
            public void onClick(View v) 
                displayTextView();
            
        );
    

    @Override
    public void onEmojiDelete() 
        String text = editText.getText().toString();
        if (text.isEmpty()) 
            return;
        
        if ("]".equals(text.substring(text.length() - 1, text.length()))) 
            int index = text.lastIndexOf("[");
            if (index == -1) 
                int action = KeyEvent.ACTION_DOWN;
                int code = KeyEvent.KEYCODE_DEL;
                KeyEvent event = new KeyEvent(action, code);
                editText.onKeyDown(KeyEvent.KEYCODE_DEL, event);
                //displayTextView();
                return;
            
            editText.getText().delete(index, text.length());
            //displayTextView();
            return;
        
        int action = KeyEvent.ACTION_DOWN;
        int code = KeyEvent.KEYCODE_DEL;
        KeyEvent event = new KeyEvent(action, code);
        editText.onKeyDown(KeyEvent.KEYCODE_DEL, event);
        //displayTextView();
    

    private void displayTextView() 
        try 
            EmojiUtil.handlerEmojiText(textView, editText.getText().toString(), this);
         catch (IOException e) 
            e.printStackTrace();
        
    


    @Override
    public void onEmojiClick(Emoji emoji) 
        if (emoji != null) 
            int index = editText.getSelectionStart();
            Editable editable = editText.getEditableText();
            if (index < 0) 
                editable.append(emoji.getContent());
             else 
                editable.insert(index, emoji.getContent());
            
        
        //displayTextView();
    



以上是关于评论页面表情处理(emoji)的主要内容,如果未能解决你的问题,请参考以下文章

emoji表情处理,emoji表情的编码解码

PHP Mysql字符集utf8mb4支持Emoji表情

Java 微信端评论表情处理

手机QQ空间emoji表情输不出怎么办

手机qq空间如何使用emoji表情

怎样在手机qq空间上使用emoji表情