java - 如何在strings.xml中使用href
问题描述
strings.xml 中的字符串
<string name="lblAuthor1">Icon made by <a href="https://www.flaticon.com/authors/smashicons">Smashicons</a> from
<a href="https://www.flaticon.com">www.flaticon.com</a></string>
活动中
TextView lblAuthor1 = findViewById(R.id.lblAuthor1);
lblAuthor1.setText(getText(R.string.lblAuthor1));
lblAuthor1.setMovementMethod(LinkMovementMethod.getInstance());
在这个答案中,我读到
我应该只使用
<b>, <i> and <u>
文档中列出的它们。
但由于某种原因,a href tag
我的应用程序中的作品,所以我想知道这是否会导致任何问题,因为文档不包括a href
在 strings.xml 中使用它时支持的内容
解决方案
方法一
像这样更改您的代码
if (Build.VERSION.SDK_INT >= 24) {
lblAuthor1.setText(Html.fromHtml(getText(R.string.lblAuthor1), Html.FROM_HTML_MODE_LEGACY));
} else {
lblAuthor1.setText(Html.fromHtml(getText(R.string.lblAuthor1)));
}
代替
lblAuthor1.setText(getText(R.string.lblAuthor1));
方法二
关注这个答案
推荐阅读
- spring-boot - Gradle 找不到插件,使用 Spring 初始化程序初始化的 Spring Boot 项目
- javascript - 导出已在导出函数中使用的变量
- asp.net-web-api - 哪种 Insights 实施可以保证记录所有异常?
- java - 默认情况下使用依赖项启用 Spring 自动配置
- r - 如何为绘图中曲线下的区域着色
- angular - 无法以角度访问子组件的第二级
- c - 这个关于指针运算符的陈述是什么意思?"& 只能与变量一起使用,* 可以与变量、常量或表达式一起使用。"
- angular - 饼图在 Angular 中显示输入数据
- swift - 为什么 NSPredicate 和 DateComponents 不起作用
- ios - 如何使用 Stripe API 确认 Apple Pay 付款