如何合并一些spannable对象?
我将一个可以跨越的对象分成三部分,做不同的操作,然后我需要合并它们。
Spannable str = editText.getText(); Spannable selectionSpannable = new SpannableStringBuilder(str, selectionStart, selectionEnd); Spannable endOfModifiedSpannable = new SpannableStringBuilder(str, selectionEnd, editText.getText().length()); Spannable beginningOfModifiedSpannable = new SpannableStringBuilder(str, 0, selectionStart);
我该怎么做? 我没有find所需的方法或构造函数来做到这一点。
你可以使用这个:
TextUtils.concat(span1, span2);
http://developer.android.com/reference/android/text/TextUtils.html#concat(java.lang.CharSequence中…)
谢谢,它的工作。 我注意到我可以合并3个可以跨越的对象:
(Spanned) TextUtils.concat(foo, bar, baz)
我知道这很旧。 但修改kotlin stdlib后,我有这个代码:
fun Iterable .joinToSpannedString(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "", limit: Int = -1, truncated: CharSequence = "...", transform: ((T) -> CharSequence)? = null): SpannedString { return joinTo(SpannableStringBuilder(), separator, prefix, postfix, limit, truncated, transform) .let { SpannedString(it) } }
希望它可以帮助某人。
- 用Kotlin在Android中线程安全的全局资源
- Kotlin并行协程
- 黄瓜测试不按指定顺序运行,有什么不对?
- lateinit属性主持人还没有被EasyMVP,Robolectric和Kotlin初始化
- RecyclerView不可滚动,并且项目单击不在导航抽屉recyclerview中工作
- 在kotlin中写入可分配的值
- 在Instant App中应用插件“kotlin-android”会导致“null不能转换为非空types的com.android.build.gradleBasePlugin”
- 未解决的参考DaggerApplicationComponent
- android studio 3.0.1和kotlin v1.2.10-release-Studio3.0-1有问题