2013-02-04 27 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);