在edittext中为某些单词添加波浪形红色下划线

时间:2013-05-28 05:36:20

标签: android android-edittext html underline

我正在编写代码编辑器,如果用户在他编写的代码中出错,我正在尝试动态添加红色波浪下划线。我尝试使用 underlineSpan ,但我不知道如何使它变得波浪状。使用.setColor()更改颜色似乎也不起作用。是否有 Span 可以帮助我,或者有没有办法通过 Paint 实现这一目标?

1 个答案:

答案 0 :(得分:0)

您可以使用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);

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