简体   繁体   English

循环中的多个 spannableString.setSpan

[英]Multiple spannableString.setSpan in a loop

I'm creating a calculator app using Kotlin.我正在使用 Kotlin 创建一个计算器应用程序。 I want to highlight the operation characters (+, -, *, /) by making their color blue.我想通过将它们的颜色设为蓝色来突出显示操作字符(+、-、*、/)。 The array operationsInStrings is filled with indexes of characters from string that I wish to change the color to blue.数组 operationsInStrings 填充了我希望将颜色更改为蓝色的字符串中的字符索引。 Only the last member of the array turns to blue color Emulator screenshot .只有数组的最后一个成员变成蓝色Emulator screenshot I tried using both spannableString and SpannableStringBuilder, but I'm probably doing something wrong as I'm new to the language.我尝试同时使用 spannableString 和 SpannableStringBuilder,但我可能做错了,因为我是该语言的新手。 The array is filled correctly, as I tested it.正如我测试的那样,该数组已正确填充。 Function code功能码

A single span can only have one location within a SpannableString or SpannableStringBuilder.单个跨度在 SpannableString 或 SpannableStringBuilder 中只能有一个位置。 To color multiple ranges, you need to create a different span for each range.要为多个范围着色,您需要为每个范围创建不同的跨度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM