我需要以编程方式在带有html格式的textview中显示字符串,例如。 “找到更多信息”+这里“,”这里“可以听取onclick。 这可能或任何其他建议?
你可以使用SpannableString
和ClickableSpan
。这是一个例子。
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());