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());