如何使用fromHTML打开URL?

时间:2018-03-01 07:45:54

标签: java android html webview fromhtml

我想使用url打开Html.fromHtml(),标签之间的特定文字也应该是绿色而不是下划线。

我现在该怎么做?我这样做:

consent = consent.replace("<clickable>", "<a href=\"https://www.google.com/\"").replace("</clickable>", "</a>");
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
    consentCheck.setText(Html.fromHtml(consent, Html.FROM_HTML_MODE_LEGACY));
} else {
    consentCheck.setText(Html.fromHtml(consent));
}

1 个答案:

答案 0 :(得分:0)

你试过了吗?

textView.setMovementMethod(LinkMovementMethod.getInstance());

改变颜色:

String blue = "this is blue";
SpannableString blueSpannable = new SpannableString(blue);
blueSpannable.setSpan(new ForegroundColorSpan(Color.BLUE), 0, blue.length(), 0);
builder.append(blueSpannable);

mTextView.setText(builder, BufferType.SPANNABLE);