为edittext中的一些单词画一条红色波浪线



我正在制作一个代码编辑器,我正在尝试动态地添加一个红色波浪下划线,如果用户在他写的代码中犯了错误。我试过使用underlineSpan,但我不知道如何使它波浪。使用. setcolor()更改颜色似乎也不起作用。是否有一个Span可以帮助我,或者有一种方法来实现与油漆 ?

你可以使用TextPaint

TextPaint tp = new TextPaint();
tp.linkColor = Color.BLACK;  //you can use your color using Color.parseColor("#123456");   
UnderlineSpan us = new UnderlineSpan();
us.updateDrawState(tp);
SpannableString sp = new SpannableString("Welcome to android");
sp.setSpan(us, 11, 18, 0); // UnderlineSpan Object, Start position, End position, Flag.
et.setText(sp);

这对我有用。我希望这对你有帮助。

最新更新