onTextChanged函数在保存edittext颜色时无法正常工作 [英] onTextChanged function does not work correctly in saving edittext colors
本文介绍了onTextChanged函数在保存edittext颜色时无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试动态保存具有不同颜色的编辑文本,但是当我通过将其转换为HTML格式进行保存时,它只将文本保存为一种颜色而不是我选择的颜色。
I am trying to save edit text with different colors dynamically but when I save it by converting it into HTML form it only saves the text in one color and not in the colors that I selected.
这是Textchanged,str是可跨越的文本。
Here is the Textchanged, str is the spannable text.
text.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(start < s.length() - 1 || count > before){
str.setSpan(new ForegroundColorSpan(Color.parseColor(txtColor)), start,start+1 , Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
推荐答案
在您的文本更改后尝试此操作,它将解决你的问题。
try this in your after text changes and it will solve your problem.
public void afterTextChanged(Editable s) {
str.removeSpan(new ForegroundColorSpan(Color.parseColor(currentColor)));
}
这篇关于onTextChanged函数在保存edittext颜色时无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文