[英]How to make a anchor tag clickable which is inside paragraph tag?
Below is my string 下面是我的字符串
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>";
I need the anchor tag to be clickable in Android. 我需要在Android中点击锚标记。 What I have tried so far is 到目前为止我尝试过的是
txtJobLink.setText(""+Html.fromHtml(txtLink));
txtJobLink.setMovementMethod(BetterLinkMovementMethod.newInstance());
BetterLinkMovementMethod.linkify(Linkify.ALL,txtJobLink);
BetterLinkMovementMethod.linkifyHtml(txtJobLink);
txtJobLink.setLinksClickable(true);
If you have added added autoLink
and linksClickable
properties in TextView
in your xml file then please remove it. 如果您已在xml文件中的TextView
中添加了添加的autoLink
和linksClickable
属性,请将其删除。
And Change your Activity code like: 并更改您的活动代码,如:
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));
}
So now your layout will be like: 所以现在你的布局将是:
When you will click on "careers page", it will open associated url in web browser. 当您点击“职业页面”时,它将在网络浏览器中打开相关网址。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.