如何更改 Android TextView 的省略号字符串?(... to ...more) [英] How to change the ellipsis string of Android TextView?(... to ...more)
问题描述
我想将省略号字符串从 ... 更改为自定义字符串,例如 abc...[more]
.但是在TextUtil中,省略号字符串是固定的:
private static final String ELLIPSIS_STRING = new String(ELLIPSIS_NORMAL);
我很惊讶还没有任何好的解决方案,所以我花了一些时间编写了自己的自定义 TextView,它允许您显示自定义省略号.我在开发它时想到的几件事:
- TextView 不应多次绘制文本,因为这是一项繁重的操作,可能会影响性能.
- 它应该尊重 Spanned 字符串.
- 支持省略号的自定义文本颜色.
看看,如果你发现任何问题,请告诉我:
I want to change the ellipsis string from ... to custom string, such as abc...[more]
.
But in TextUtil, the ellipsis string is fixed:
private static final String ELLIPSIS_STRING = new String(ELLIPSIS_NORMAL);
I was surprised that there isn't any good solution to that yet, so I spent sometime and wrote my own custom TextView which allows you to show a custom ellipsis. Few things I had in mind while developing it:
- The TextView shouldn't draw the text more than once since this is a heavy operation and could compromise the performance.
- It should respect Spanned strings.
- Support custom text color for the ellipsis.
Have a look and let me know if you find any issues: https://github.com/TheCodeYard/EllipsizedTextView
And here's a screenshot:
这篇关于如何更改 Android TextView 的省略号字符串?(... to ...more)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!