发现有的表情占一个长度,有的表情占2个长度,于是就如下兼容
- val index = etSend.selectionStart
- deleteText(index)
- fun deleteText(index:Int) {
- if (index > 0) {
- val text1 = etSend.text.toString().substringV2(index-1,index)
- val text2 = etSend.text.toString().substringV2(index-2,index)
- Log.i("deleteText", "deleteText: "+text1+" / "+text1.length + " / "+AndroidEmoji.isEmoji(text1))
- Log.i("deleteText", "deleteText: "+text1.length)
- if (AndroidEmoji.isEmoji(text1)){
- etSend.text?.delete(index-1, index)
- return
- }
- if (AndroidEmoji.isEmoji(text2)&&text2.length==2){
- etSend.text?.delete(index-2, index)
- }else{
- etSend.text?.delete(index-1, index)
- }
- }
- }