问题描述
我做了一个类似于whatsapp的android应用。我有一个状态机制。在显示状态时,它不会进行超链接。我尝试了很多方法,但其他方法都抛出错误。请帮助
解决方法
使用Java代码:
TextView textView =(TextView)findViewById(R.id.textView);
textView.setClickable(true);
textView.setMovementMethod(LinkMovementMethod.getInstance());
String text = "<a href='http://www.facebook.com'> Facebook </a>";
textView.setText(Html.fromHtml(text));
// From API level >= 24 onwards Html.fromHtml(String source) is deprecated instead use fromHtml(String,int)
textView.setText(Html.fromHtml(text,Html.FROM_HTML_MODE_COMPACT));
或在布局XML文件中的TextView小部件属性内
android:autoLink="web"
android:linksClickable="true"