public abstract class ClickableLinkSpan extends ClickableSpan{ private int selectedColor; public int linkColor; private boolean colored; private boolean underlined; private boolean selected; /** * * @param selectedColor 选中时的背景色 * @param linkColor 文字颜色 * @param underlined 是否显示下划线 */ public ClickableLinkSpan(int selectedColor, int linkColor, boolean underlined) { this(selectedColor, linkColor, true, true, underlined); } ClickableLinkSpan(int selectedColor, int linkColor, boolean colored,boolean selected, boolean underlined) { this.selectedColor = selectedColor; this.linkColor = linkColor; this.colored = colored; this.underlined = underlined; this.selected = selected; } @Override public void updateDrawState(TextPaint ds) { if (colored) { ds.setColor(linkColor); }else { ds.setColor(ds.linkColor); } if (selected) { ds.bgColor = selectedColor; }else { ds.bgColor = Color.TRANSPARENT; } // 设置是否显示下划线 ds.setUnderlineText(underlined); } }
时间: 2024-10-05 07:04:50