From e2095f6e469e2e53b47442547d9a5bf73957bbc6 Mon Sep 17 00:00:00 2001 From: 18401019693 Date: Sat, 8 Oct 2022 18:24:05 +0800 Subject: [PATCH] =?UTF-8?q?@=E6=B6=88=E6=81=AF=E7=95=8C=E9=9D=A2=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E9=80=BB=E8=BE=91=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yunbao/common/views/weight/AtTextWatcher.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/com/yunbao/common/views/weight/AtTextWatcher.java b/common/src/main/java/com/yunbao/common/views/weight/AtTextWatcher.java index ba85825e8..e0a8807ba 100644 --- a/common/src/main/java/com/yunbao/common/views/weight/AtTextWatcher.java +++ b/common/src/main/java/com/yunbao/common/views/weight/AtTextWatcher.java @@ -7,7 +7,6 @@ import android.text.SpannableStringBuilder; import android.text.TextUtils; import android.text.TextWatcher; import android.view.KeyEvent; -import android.view.View; import android.widget.EditText; import com.yunbao.common.bean.OlineUserlistModel; @@ -30,7 +29,7 @@ public class AtTextWatcher implements TextWatcher { public void insertTextForAt(OlineUserlistModel model, EditText input) { this.input = input; if (!spanMap.containsKey(model.getId())) { - if (!TextUtils.isEmpty(input.getText())){ + if (!TextUtils.isEmpty(input.getText())) { spannableStringBuilder = new SpannableStringBuilder(input.getText()); } String nameStr = model.getUserNicename(); @@ -38,11 +37,16 @@ public class AtTextWatcher implements TextWatcher { int endIndex = startIndex + nameStr.length();//字符结束的位置 spanMap.put(model.getId(), model); //插入要添加的字符,此处是为了给span占位 - input.getText().insert(startIndex, "@" + nameStr); + input.getText().insert(startIndex, "@" + nameStr + " "); //1、使用mEditText构造一个SpannableString StringBuffer atName = new StringBuffer(); - atName.append("@").append(nameStr); - spannableStringBuilder.append(atName.toString()); + atName.append("@").append(nameStr).append(" "); + if (spannableStringBuilder.length() > 0) { + spannableStringBuilder.insert(startIndex, atName.toString()); + } else { + spannableStringBuilder.append(atName.toString()); + } + AtUserForegroundColorSpan span = new AtUserForegroundColorSpan(Color.parseColor("#2a92f7")); span.setAtContent(atName.toString()); span.setUid(model.getId());