protected BottomBarBadge( Context context, int position, final View tabToAddTo, // Rhyming accidentally! That's a Smoove Move! int backgroundColor) { super(context); ViewGroup.LayoutParams params = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); setLayoutParams(params); setGravity(Gravity.CENTER); MiscUtils.setTextAppearance(this, R.style.BB_BottomBarBadge_Text); int three = MiscUtils.dpToPixel(context, 3); ShapeDrawable backgroundCircle = BadgeCircle.make(three * 3, backgroundColor); setPadding(three, three, three, three); setBackgroundCompat(backgroundCircle); FrameLayout container = new FrameLayout(context); container.setLayoutParams(params); ViewGroup parent = (ViewGroup) tabToAddTo.getParent(); parent.removeView(tabToAddTo); container.setTag(tabToAddTo.getTag()); container.addView(tabToAddTo); container.addView(this); parent.addView(container, position); container .getViewTreeObserver() .addOnGlobalLayoutListener( new ViewTreeObserver.OnGlobalLayoutListener() { @SuppressWarnings("deprecation") @Override public void onGlobalLayout() { adjustPositionAndSize(tabToAddTo); } }); }