简体   繁体   English

从TextView Android提取多种颜色

[英]Extracting multiple colors from a TextView Android

So I know that to extract a color from the TextView you would use getCurrentTextColor() but my textView contains multiple colors in it. 所以我知道要从TextView中提取颜色,可以使用getCurrentTextColor(),但是我的textView中包含多种颜色。 How can I preserve and extract this data? 如何保存和提取这些数据? I need the color to do some blackbox testing for my application ie when a key is pressed, a part of the textview is changed but not all. 我需要颜色来对我的应用程序进行一些黑盒测试,即当按下某个键时,部分textview会更改,但不是全部。 I'm trying to test if that part is changed so i need to extract that data. 我正在尝试测试该部分是否已更改,因此我需要提取该数据。

What you probably need to do is use getText() to retrieve a SpannableString . 您可能需要做的是使用getText()检索SpannableString You can then extract the Span s and for each Span get the markup objects associated with it. 然后,您可以提取Span并为每个Span获取与其关联的标记对象。 The markup will usually be classes in android.text.style : probably ForegroundColorSpan is what you're looking for. 标记通常是android.text.style中的类:您可能正在寻找ForegroundColorSpan

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

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