A Qadeer Qureshi
A Qadeer Qureshi

Reputation: 343

how to get background color of textview in robotium

Hi guys i m trying to get the background color of the TextView but unable to find it.

I am doing sanity automation testing of my chat app using robotium.

Main objective is to find weather textview bubble color is grey or blue and put assertion.

    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 i m 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 :)

Upvotes: 0

Views: 766

Answers (1)

gionnut
gionnut

Reputation: 99

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

For more read here:

colors.xml not generating the correct values in gen/R file?

Hope it helps, cheers.

Upvotes: 1

Related Questions