简体   繁体   中英

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.

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 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

For more read here:

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

Hope it helps, cheers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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