首页 > 代码库 > edittext实现粘贴表情
edittext实现粘贴表情
1 package com.sixin.view; 2 3 import com.sixin.utile.FaceDataUtil; 4 import android.annotation.SuppressLint; 5 import android.content.Context; 6 import android.text.Editable; 7 import android.util.AttributeSet; 8 import android.widget.EditText; 9 10 public class CustomEditView extends EditText {11 private static final int ID_PASTE = android.R.id.paste;12 13 public CustomEditView(Context context, AttributeSet attrs) {14 super(context, attrs);15 }16 17 @SuppressLint("NewApi")18 @Override19 public boolean onTextContextMenuItem(int id) {20 if (id == ID_PASTE) {21 try {22 int currentapiVersion = android.os.Build.VERSION.SDK_INT;23 if (currentapiVersion >= android.os.Build.VERSION_CODES.HONEYCOMB) {24 android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);25 String value =http://www.mamicode.com/ clipboard.getText().toString();26 Editable edit = getEditableText();27 // edit.clear();28 int index = this.getSelectionStart();29 if (index < 0 || index >= edit.length()) {30 edit.append(FaceDataUtil.getIns(getContext()).getExpressionString(getContext(), value, 0.7f));31 } else {32 edit.insert(index, FaceDataUtil.getIns(getContext()).getExpressionString(getContext(), value, 0.7f));// 光标所在位置插入文字33 }34 35 } else {36 android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);37 String value =http://www.mamicode.com/ clipboard.getText().toString();38 Editable edit = getEditableText();39 // edit.clear();40 int index = this.getSelectionStart();41 if (index < 0 || index >= edit.length()) {42 edit.append(FaceDataUtil.getIns(getContext()).getExpressionString(getContext(), value, 0.7f));43 } else {44 edit.insert(index, FaceDataUtil.getIns(getContext()).getExpressionString(getContext(), value, 0.7f));// 光标所在位置插入文字45 }46 }47 return true;48 } catch (Exception e) {49 e.printStackTrace();50 }51 }52 return super.onTextContextMenuItem(id);53 }54 55 }
edittext实现粘贴表情
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。