handle textview link click in my android app

前端 未结 12 1177
迷失自我
迷失自我 2020-11-22 04:33

I\'m currently rendering HTML input in a TextView like so:

tv.setText(Html.fromHtml(\"test\"));

The HTML b

12条回答
  •  猫巷女王i
    2020-11-22 05:00

    public static void setTextViewFromHtmlWithLinkClickable(TextView textView, String text) {
        Spanned result;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
            result = Html.fromHtml(text, Html.FROM_HTML_MODE_LEGACY);
        } else {
            result = Html.fromHtml(text);
        }
        textView.setText(result);
        textView.setMovementMethod(LinkMovementMethod.getInstance());
    }
    

提交回复
热议问题