https://gitee.com/Pino_W/ait.git
记录一下
mBinding.atEdittext.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // 从start开始的count个字符将会被一个新的长度为after的文本替换,注意这里是将被替换,还没有被替换 Editable editable = mBinding.atEdittext.getText(); // 光标起始为止如果不是在最后,那对于在光标后面的文字块都要做偏移 if (start < editable.length()) { int end = start + count; int offset = after - count; whenDelText(start, end, offset); } }
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (count == 1 && !TextUtils.isEmpty(s)) {
char mentionChar = s.toString().charAt(start);
int selectionStart = mBinding.atEdittext.getSelectionStart();
if (mentionChar == '@') {
mPresenter.getData(page, pageNum);
// 这里是把刚刚输入的@删除掉
mBinding.atEdittext.getText().delete(selectionStart - 1, selectionStart);
}
// else if (mentionChar == ‘#’) { // startActivityForResult(TopicListActivity.getTopicListIntent(MainActivity.this), REQUEST_TAG_APPEND); // et_view.getText().delete(selectionStart - 1, selectionStart); // } }
}
@Override
public void afterTextChanged(Editable s) {
if (s.length() > 0) {
setBtnBg();
} else {
if (videoList.size() <= 0 && photoAdapter.getmList().size() <= 0 && mVicePath == null) {
setBtnBgNormal();
}
}
}
});
|