带onclicklistener的HTML文本[关闭]

问题描述 投票:-2回答:1

我需要以编程方式在带有html格式的textview中显示字符串,例如。 “找到更多信息”+这里“,”这里“可以听取onclick。 这可能或任何其他建议?

android html string onclicklistener
1个回答
0
投票

你可以使用SpannableStringClickableSpan。这是一个例子。

SpannableString span= new SpannableString("Find more information "+here"");
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View textView) {
    // Perform action here
}
@Override
public void updateDrawState(TextPaint ds) {
    super.updateDrawState(ds);
    ds.setUnderlineText(false);
}
};
span.setSpan(clickableSpan, 23, 26, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(span);
textView.setMovementMethod(LinkMovementMethod.getInstance());
© www.soinside.com 2019 - 2024. All rights reserved.