我们首先来分析一下QuickContactBadge源码
在QuickContactBadge构造函数中会给mOverlay赋值
private Drawable mOverlay;
public QuickContactBadge(
Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes); TypedArray styledAttributes = mContext.obtainStyledAttributes(R.styleable.Theme);
mOverlay = styledAttributes.getDrawable(
com.android.internal.R.styleable.Theme_quickContactBadgeOverlay);
styledAttributes.recycle(); if (!isInEditMode()) {
mQueryHandler = new QueryHandler(mContext.getContentResolver());
}
setOnClickListener(this);
}
所以我是利用java反射机制给mOverlay赋值为空
QuickContactBadge headImage = (QuickContactBadge)findViewById(R.id.head_image);
//利用反射机制给QuickContactBadge.mOverlay复制为null
try {
Field f = headImage.getClass().getDeclaredField("mOverlay");
f.setAccessible(true);
f.set(headImage,null);
} catch (Exception e) {
e.printStackTrace();
}
效果图如下: