下面是我的字符串
String txtLink = "<p>Apply directly in our <a
href=\"https://theorem.applytojob.com/apply/TyJy6YCsOs/Experienced-
Backend-Engineer-Ruby?source=GitHub+Jobs\">careers page</a></p>";
我需要在Android中点击锚标记。到目前为止,我尝试过的是
txtJobLink.setText(""+Html.fromHtml(txtLink));
txtJobLink.setMovementMethod(BetterLinkMovementMethod.newInstance());
BetterLinkMovementMethod.linkify(Linkify.ALL,txtJobLink);
BetterLinkMovementMethod.linkifyHtml(txtJobLink);
txtJobLink.setLinksClickable(true);
答案 0 :(得分:0)
如果您在XML文件的autoLink
中添加了linksClickable
和TextView
属性,请删除它。
并更改您的活动代码,例如:
String txtLink = "<p>Apply directly in our <a href=\"https://theorem.applytojob.com/apply/TyJy6YCsOs/Experienced-Backend-Engineer-Ruby?source=GitHub+Jobs\">careers page</a></p>";
TextView txtJobLink = findViewById(R.id.txtJobLink);
txtJobLink.setMovementMethod(LinkMovementMethod.getInstance());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
txtJobLink.setText(Html.fromHtml(txtLink, Html.FROM_HTML_MODE_LEGACY));
} else {
txtJobLink.setText(Html.fromHtml(txtLink));
}
所以现在您的布局将是:
当您单击“职业页面”时,它将在Web浏览器中打开关联的URL。