繁体   English   中英

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

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

大家好,我试图获取TextView的背景颜色,但找不到它。

我正在使用robotium对聊天应用程序进行健全性自动化测试。

主要目的是找到天气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 

            }
        }
    }

这就是我试图获得色彩但有恐惧感的东西

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

请帮助我,谢谢:)

经过一些研究,您可以从文本视图中使用

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

问题是返回的文本颜色是R.java中的一种,而不是xml中使用的一种。

欲了解更多信息,请点击这里:

colors.xml无法在gen / R文件中生成正确的值?

希望能有所帮助,欢呼。

暂无
暂无

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

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