Get color of an element using calabash-android

﹥>﹥吖頭↗ 提交于 2019-12-06 09:28:57

问题


I have a text field(EditView) in my Android app, which changes color (borders) if it's value is not valid or empty. Also label(TextView) changes its color too in this case.

When I'm trying to get TextView using query, I see the following:

[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"
}

If i need to get text I can use query("TextView id:'field_label'", :text)

Is there any way in calabash to get the color of the TextView?


回答1:


Unfortunately this is not possible in Android.

In Android the Views (also the TextView) can have almost anything as a background not just a color (a bitmap, a shape, a gradient color, etc). Because of this there is no way to get the background color of a view (it is not stored).

This is not a limitation of Calabash but the Android system. You can get any property of an Android view if it is accessible.

You can query the following colors on the TextView (nothing is background):

  • text color :currentTextColor
  • hintTextColor :hintTextColor
  • highlight color :highlightColor
  • shadow color :shadowColor


来源:https://stackoverflow.com/questions/21185624/get-color-of-an-element-using-calabash-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!