QuickContactBadge去掉三角

我们首先来分析一下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();
		} 



效果图如下:



posted @ 2015-01-10 22:57  安辉  阅读(353)  评论(0编辑  收藏  举报