如何更改 Android TextView 的省略号字符串?(... to ...more) [英] How to change the ellipsis string of Android TextView?(... to ...more)

查看:30
本文介绍了如何更改 Android TextView 的省略号字符串?(... to ...more)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将省略号字符串从 ... 更改为自定义字符串,例如 abc...[more].但是在TextUtil中,省略号字符串是固定的:

private static final String ELLIPSIS_STRING = new String(ELLIPSIS_NORMAL);

解决方案

我很惊讶还没有任何好的解决方案,所以我花了一些时间编写了自己的自定义 TextView,它允许您显示自定义省略号.我在开发它时想到的几件事:

  1. TextView 不应多次绘制文本,因为这是一项繁重的操作,可能会影响性能.
  2. 它应该尊重 Spanned 字符串.
  3. 支持省略号的自定义文本颜色.

看看,如果你发现任何问题,请告诉我:

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:

  1. The TextView shouldn't draw the text more than once since this is a heavy operation and could compromise the performance.
  2. It should respect Spanned strings.
  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆