如何使用FromHTML打开URL



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

我现在该怎么做:

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));
}

您是否尝试过:

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);

最新更新