2013-02-04 28 views
0

我创建了自定义ImageView。获取自定义ImageView的背景颜色

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

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

    } 
} 

如何使用obtainStyledAttributes获取imageview的背景颜色?

回答

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

int color = defaultTypedArray.getColor(0, Color.TRANSPARENT);