TextView text=(TextView) findViewById(R.id.text);
String value = "<html> click to go <font color=#757b86><b><a href=\"http://www.google.com\">google</a></b></font> </html>";
Spannable spannedText = (Spannable)
Html.fromHtml(value);
text.setMovementMethod(LinkMovementMethod.getInstance());
Spannable processedText = removeUnderlines(spannedText);
text.setText(processedText);
這裏是你的removeUnderlines()
public static Spannable removeUnderlines(Spannable p_Text) {
URLSpan[] spans = p_Text.getSpans(0, p_Text.length(), URLSpan.class);
for (URLSpan span : spans) {
int start = p_Text.getSpanStart(span);
int end = p_Text.getSpanEnd(span);
p_Text.removeSpan(span);
span = new URLSpanNoUnderline(span.getURL());
p_Text.setSpan(span, start, end, 0);
}
return p_Text;
}
也使用此行來創建類URLSpanNoUnderline.java
import co.questapp.quest.R;
import android.text.TextPaint;
import android.text.style.URLSpan;
public class URLSpanNoUnderline extends URLSpan {
public URLSpanNoUnderline(String p_Url) {
super(p_Url);
}
@Override
public void updateDrawState(TextPaint p_DrawState) {
super.updateDrawState(p_DrawState);
p_DrawState.setUnderlineText(false);
p_DrawState.setColor(R.color.info_text_color);
}
}
你也可以改變文本的顏色p_DrawState.setColor(R.color.info_text_color);
這裏有一個很棒的答案在這裏:http://stackoverflow.com/questions/4096851/remove-underline-from-links-in-textview-android – Warpzit
是啊之前發佈問題我謝謝你的回答,但我在這裏已經提到過,我沒有使用Linkify或其他任何東西,除了 setMovementMethod(LinkMovementMethod.getInstance()); 但無論如何。 – shankey
感謝您的編輯[email protected] – shankey