簡體   English   中英

使用calabash-android獲取元素的顏色

[英]Get color of an element using calabash-android

我的Android應用程序中有一個文本字段(EditView),如果其值無效或為空,它將更改顏色(邊界)。 在這種情況下,label(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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM