使用calabash-android获取元素的颜色
我的Android应用程序中有一个文本字段(EditView),如果它的值无效或为空,它会更改颜色(边框)。 在这种情况下,标签(TextView)也会更改其颜色。
当我尝试使用query
获取TextView时,我看到以下内容:
[0] { "id" => "field_lable", "enabled" => true, "contentDescription" => nil, "class" => "android.widget.TextView", "text" => "Name", "rect" => { "center_y" => 198.5, "center_x" => 51.0, "height" => 27, "y" => 185, "width" => 82, "x" => 10 }, "description" => "android.widget.TextView@a28btb00" }
如果我需要获取文本,我可以使用query("TextView id:'field_label'", :text)
在葫芦中有没有办法获得TextView的颜色?
不幸的是,这在Android中是不可能的。
在Android中, Views
(也是TextView
)几乎可以作为背景而不仅仅是一种颜色(位图,形状,渐变颜色等)。 因此,无法获取视图的背景颜色(不存储)。
这不是Calabash的限制,而是Android系统。 如果可以访问,您可以获取Android视图的任何属性。
您可以在TextView上查询以下颜色(没有任何背景):
- 文字颜色
:currentTextColor
- hintTextColor
:hintTextColor
- 高亮颜色
:highlightColor
- 阴影颜色
:shadowColor