下划线文本视图
只是一个简单的问题: 你知道为什么我可以这样做吗:
pnrCode = (TextView)findViewById(R.id.pnr);
SpannableString pnrContent = new SpannableString("PNR: ");
pnrContent.setSpan(new UnderlineSpan(), 0, pnrContent.length(), 0);
pnrCode.setText(pnrContent + BookingSettings.getBookingSegment().substring(0, 6));
文本没有下划线。
然而,如果我只这样做:
pnrCode = (TextView)findViewById(R.id.pnr);
SpannableString pnrContent = new SpannableString("PNR: ");
pnrContent.setSpan(new UnderlineSpan(), 0, pnrContent.length(), 0);
pnrCode.setText(pnrContent);
文本带有下划线。
我必须创建两个文本视图? 你知道另一种解决方案吗?
如有任何帮助,我们将不胜感激;)
Just a quick question:
Do you know why i can do that:
pnrCode = (TextView)findViewById(R.id.pnr);
SpannableString pnrContent = new SpannableString("PNR: ");
pnrContent.setSpan(new UnderlineSpan(), 0, pnrContent.length(), 0);
pnrCode.setText(pnrContent + BookingSettings.getBookingSegment().substring(0, 6));
The text is not underlined.
Whereas, if i do only that:
pnrCode = (TextView)findViewById(R.id.pnr);
SpannableString pnrContent = new SpannableString("PNR: ");
pnrContent.setSpan(new UnderlineSpan(), 0, pnrContent.length(), 0);
pnrCode.setText(pnrContent);
The text is underlined.
I have to create two textview ?
Do you know another solution ?
Any help is appreciated ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不。
pnrContent + BookingSettings.getBookingSegment().substring(0, 6)
可能会给您一个String
返回,因为我相信+ 运算符会将两边转换为
String
对象,然后执行串联。因此,您将丢失格式。相反,请使用
new SpannableString("PNR: "+ BookingSettings.getBookingSegment().substring(0, 6));
,并根据需要设置UnderlineSpan
的长度。No.
pnrContent + BookingSettings.getBookingSegment().substring(0, 6)
is probably going to give you aString
back, as I believe the+
operator will convert both sides toString
objects, then perform the concatenation. Hence, you will lose your formatting.Instead, use
new SpannableString("PNR: "+ BookingSettings.getBookingSegment().substring(0, 6));
, and set the length of theUnderlineSpan
as needed.