首先重写这个类:
该类中可以重新定义显示的字体、颜色以及下划线等
public class ClickSpan extends ClickableSpan{
String text;
@Override
public void onClick(View widget) {
// TODO Auto-generated method stub
}
public ClickSpan(){
super();
}
@Override
public void updateDrawState(TextPaint ds) {
// TODO Auto-generated method stub
//颜色下划线等
super.updateDrawState(ds);
ds.setColor(Color.parseColor("#b01313"));
ds.setUnderlineText(false);
}
}
然后使用:
htmlText = "<font color='#000000'>" + "简介:" + tv.getShow() + "</font>";
htmlText2 = "<font color='#b01313'>[+展开]</font><br/>";
htmlText3 = "<font color='#b01313'>[收回]</font><br/>";
text = Html.fromHtml(htmlText + htmlText2);
spannableString = new SpannableString(text);
spannableString.setSpan(
new ClickSpan() {
[align=left][/align]
@Override
public void onClick(View widget) {
if (flag) {
flag = false;
tv.setAll(flag);
text = Html.fromHtml("<font color='#000000'>"
+ "简介:" + tv.getShow() + "</font>"
+ htmlText3);
SpannableString spannableString2 = new SpannableString(
text);
spannableString2.setSpan(new ClickSpan() {
@Override
public void onClick(View widget) {
flag = true;
tv.setAll(flag);
content.setText(spannableString);
}
}, text.length() - 5, text.length() - 1,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
content.setText(spannableString2);
}
}
}, text.length() - 6, text.length() - 1,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
content.setText(spannableString);
content.setMovementMethod(LinkMovementMethod.getInstance());//不要忘了这句话
该类中可以重新定义显示的字体、颜色以及下划线等
public class ClickSpan extends ClickableSpan{
String text;
@Override
public void onClick(View widget) {
// TODO Auto-generated method stub
}
public ClickSpan(){
super();
}
@Override
public void updateDrawState(TextPaint ds) {
// TODO Auto-generated method stub
//颜色下划线等
super.updateDrawState(ds);
ds.setColor(Color.parseColor("#b01313"));
ds.setUnderlineText(false);
}
}
然后使用:
htmlText = "<font color='#000000'>" + "简介:" + tv.getShow() + "</font>";
htmlText2 = "<font color='#b01313'>[+展开]</font><br/>";
htmlText3 = "<font color='#b01313'>[收回]</font><br/>";
text = Html.fromHtml(htmlText + htmlText2);
spannableString = new SpannableString(text);
spannableString.setSpan(
new ClickSpan() {
[align=left][/align]
@Override
public void onClick(View widget) {
if (flag) {
flag = false;
tv.setAll(flag);
text = Html.fromHtml("<font color='#000000'>"
+ "简介:" + tv.getShow() + "</font>"
+ htmlText3);
SpannableString spannableString2 = new SpannableString(
text);
spannableString2.setSpan(new ClickSpan() {
@Override
public void onClick(View widget) {
flag = true;
tv.setAll(flag);
content.setText(spannableString);
}
}, text.length() - 5, text.length() - 1,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
content.setText(spannableString2);
}
}
}, text.length() - 6, text.length() - 1,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
content.setText(spannableString);
content.setMovementMethod(LinkMovementMethod.getInstance());//不要忘了这句话