Open emartynov opened 7 years ago
I ended up by adding ImageView
to navigation item. But code looks quite verbose:
Resources resources = getResources();
int imageSize = (int) resources.getDimension(R.dimen.main__notification_icon_size);
int leftMargin = (int) resources.getDimension(R.dimen.bottom_navigation_notification_margin_left);
notificationIcon = new ImageView(this);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(imageSize, imageSize);
params.setMargins(leftMargin, 0, 0, 0);
params.gravity = Gravity.CENTER_HORIZONTAL;
notificationIcon.setLayoutParams(params);
notificationIcon.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_icon_outdate_warning));
ViewGroup content = (ViewGroup) bottomNavigation.getChildAt(1);
ViewGroup item = (ViewGroup) content.getChildAt(index);
item.addView(notificationIcon);
My code has a bug. For the KitKat and below first child is actually LinearLayout
that holds items view. And for Lollipop and up the code bottomNavigation.getChildAt(1)
is correct since the child 0 is background
We want to show not a number but just an image as the badge. For example, an exclamation mark as error or spinner as a progress indicator. I've tried a workaround to pass drawable as a background of the badge and the empty string as badge text. That doesn't work well since it is stretching the drawable:
Are there good solution for our problem?