简体   繁体   English

如何在Robotium中获取Textview的背景色

[英]how to get background color of textview in robotium

Hi guys im trying to get the background color of the TextView but unable to find it. 大家好,我试图获取TextView的背景颜色,但找不到它。

I am doing sanity automation testing of my chat app using robotium. 我正在使用robotium对聊天应用程序进行健全性自动化测试。

Main objective is to find weather textview bubble color is grey or blue and put assertion. 主要目的是找到天气textview气泡颜色为灰色或蓝色并声明。

    ArrayList<TextView> textViewList = solo.getCurrentViews(TextView.class);

    for (TextView textview : textViewList )
    {
        if (textview != null && textview.isShown()) 
        {
            if(textview.getText().toString().equals(Message))
            {
                ColorDrawable drawable = (ColorDrawable)textview.getBackground();
                int color= drawable.getColor();
                //doing some assertion 

            }
        }
    }

this is what im trying to get color but having expception 这就是我试图获得色彩但有恐惧感的东西

    java.lang.ClassCastException: android.graphics.drawable.LayerDrawable cannot be cast to
    android.graphics.drawable.ColorDrawable

kindly help me with this thanks :) 请帮助我,谢谢:)

after some research you can get the text color from a text view using 经过一些研究,您可以从文本视图中使用

TextView text = (TextView) solo.getCurrentActivity().findViewById(R.id.TextViewColor);
text.getCurrentTextColor();

the problem is that the text color returned is the one from R.java not the one used in your xml 问题是返回的文本颜色是R.java中的一种,而不是xml中使用的一种。

For more read here: 欲了解更多信息,请点击这里:

colors.xml not generating the correct values in gen/R file? colors.xml无法在gen / R文件中生成正确的值?

Hope it helps, cheers. 希望能有所帮助,欢呼。

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

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