0

我确实创建了一个自定义 ImageView。

我正在尝试在构造函数中获取 ImageView 的背景颜色。

public class CustomImageView extends ImageView{
    public CustomImageView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);

    }
}

如何使用 gainStyledAttributes 获取图像视图的背景颜色?

4

1 回答 1

2
// Set background
TypedArray defaultTypedArray = context.obtainStyledAttributes(attrs, 
                                                new int[] {android.R.attr.background});

int color = defaultTypedArray.getColor(0, Color.TRANSPARENT);
于 2013-02-04T10:59:00.063 回答