android - Not able to use HTML text in setText of collapsing Toolbar in android?
问题描述
I am using collapsing Toolbar
layout in my android application. while layout is collapse or expand in both case I need collapsing Toolbar
text displaying my "amount" in green and "balance" in red.
I had try to use HTML like below:
collapsingToolbar.setTitle(Html.fromHtml("<font color='green'>50</font><font color='red'>balance</font>"));
I had used SpannableString
like below:
String part1 = " 50";
String part2 = "Balance";
SpannableString str = new SpannableString(part1 + part2);
str.setSpan(new ForegroundColorSpan(Color.parseColor("#ff0000")), part1.length(), str.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
collapsingToolbar.setTitle(str);
Both did not work in my case. Dose someone have some new idea to work in this case.
解决方案
您应该在 Toolbar 小部件内添加一个 TextView 并将其文本设置为 HTML 格式的文本。
推荐阅读
- java - 如何在域层中标记主/默认构造函数
- firebase - 如何使用 SIM800 通过 HTTPS 请求调用谷歌云功能
- javascript - ReactJS:查找要在将调度操作的函数中使用的特定请求的 id
- excel - 如何查找/运行 RefreshAll?
- security - npm 漏洞需要手动审查 npm 审计修复不起作用
- java - 在 MicronautProject 中,使用休眠规范会抛出异常:Could not gain transaction-synchronized Session for current thread
- python - appName 函数有什么问题?
- android - 当我使用 ndk 构建 ffmpeg 时,它不会为 libavresample 和 libpostproc 创建 .so 和 .a 文件
- php - 无法安装laravel
- javascript - 单击Item时如何进行CSS过渡?