Try with ImageView instead of QuickContactBadge
QuickContactBadge overlay
-
07-03-2022 - |
Question
I am using a QuickContactBadge in my app and it works nicely.
However, the badge shows a small overlay in the bottom right corner. I suppose it's there to indicate that it is a QuickContactBadge
and not just a picture. I am totally fine with this, however, since I am using Holo.Light
in my app, the contact badge shows a dark overlay. In, for example, the stock dialer with Holo.Dark
, the overlay is light.
I understand the reasoning for this, however the dark overlay is just ugly on top of most contact photos, whereas the light overlay works for most.
So, how could I override the overlay, and force the badge to show the light (i.e. the one for Holo.Dark
) overlay?
Looking at the Android source for QuickContactBadge
, the Drawable
for the overlay, mOverlay
, is private and thus not directly accessible from my app. The Drawable
is set in the constructor:
public QuickContactBadge(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
TypedArray styledAttributes = mContext.obtainStyledAttributes(R.styleable.Theme);
mOverlay = styledAttributes.getDrawable(
com.android.internal.R.styleable.Theme_quickContactBadgeOverlay);
styledAttributes.recycle();
mQueryHandler = new QueryHandler(mContext.getContentResolver());
setOnClickListener(this);
}
I assume I have to extend the entire QuickContactBadge
class to solve this, but I'm fairly new to both Android and Java so I have no idea on how to do that. I've extended ListAdapter
s before, but when I try to extend this badge I run into the problem of having to access internal Android resources, which I can't.
The other solution I can think of is to "trick" the badge that I'm using Holo.Dark
but I have no idea how to do that.
Has anyone done anything similar or can at least point me in the right direction?
La solution
Autres conseils
In SDK 21 Google added a setOverlay(Drawable drawable)
method.
It accepts null, so another option to hide the decorator and keep the QuickContactBadge functionality is:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
contactBadge.setOverlay(null);
}