使用calabash-android获取元素的颜色

时间:2014-01-17 12:07:14

标签: android ruby calabash

我的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)

在calabash中有没有办法获得TextView的颜色?

1 个答案:

答案 0 :(得分:3)

不幸的是,这在Android中无法实现。

在Android中,Views(也是TextView)几乎可以作为背景而不仅仅是颜色(位图,形状,渐变颜色等)。因此,无法获得视图的背景颜色(它没有存储)。

这不是Calabash的限制,而是Android系统。如果可以访问,您可以获取Android视图的任何属性。

您可以在TextView上查询以下颜色(没有任何背景):

  • 文字颜色:currentTextColor
  • hintTextColor :hintTextColor
  • 突出显示颜色:highlightColor
  • 阴影颜色:shadowColor