get background color from textview without using ColorDrawable (API 11)

android, background, colors, textview

Solution

try this...

public static int getBackgroundColor(TextView textView) {
    ColorDrawable drawable = (ColorDrawable) textView.getBackground();
    if (Build.VERSION.SDK_INT >= 11) {
        return drawable.getColor();
    }
    try {
        Field field = drawable.getClass().getDeclaredField("mState");
        field.setAccessible(true);
        Object object = field.get(drawable);
        field = object.getClass().getDeclaredField("mUseColor");
        field.setAccessible(true);
        return field.getInt(object);
    } catch (Exception e) {
        // TODO: handle exception
    }
    return 0;
}

Problem

How can i get the backround color of a textview using only API 9? I basicly want to do this but only using API 9 ``` int intID = (ColorDrawable) textView.getBackground().getColor(); ```

Original source