我试图获得类似此图像image twitter tweet的内容。用户使用哈希标签和链接创建推文,Twitter应用程序转换为可点击链接。普通TextView无法实现这一点。我该如何创造这样的东西?请提供技术细节。
答案 0 :(得分:0)
试试这个 用户 ClickableSpan 可以实现这一目标
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View textView) {
Toast.makeText(context,"clicked", Toast.LENGTH_SHORT).show();
}
};
SpannableStringBuilder builder = new SpannableStringBuilder();
SpannableString str1 = new SpannableString("click me");
str1.setSpan(clickableSpan, 0, str1.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
str1.setSpan(new ForegroundColorSpan(Color.BLUE), 0, str1.length(), 0);
str1.setSpan(new UnderlineSpan(), 0, str1.length(), 0);
SpannableString str2 = new SpannableString("demo String 2 ");
builder.append(str2);
builder.append(str1);
Textview.setText(builder, TextView.BufferType.SPANNABLE);
Textview.setMovementMethod(LinkMovementMethod.getInstance());