2

I am using the new BottomAppBar in an app. But I can't make the badge to work. I tried using the same logic used on BottomNavigationView, but it is not working.(In another app I have a BottomNavigationView inside a BottomAppBar where the badge works, but couldn't use the same code in the BottomAppBar app(Navigation Icon).

   MenuView.ItemView itemView = (MenuView.ItemView) bottomAppBar.getChildAt(posicao);

    notificationBadge = LayoutInflater.from(this).inflate(R.layout.view_notification_badge, (ViewGroup) itemView, false);
    TextView notific = notificationBadge.findViewById(R.id.badge);
    notific.setText(notificacao);

    itemView.addView(notificationBadge);

What I want to do: enter image description here

I tried the BadgeNavigationDrawable class. But couldn't find the right reference to the navigation icon in the BottomAppBar.

Thanks.

DValdir Martins
  • 159
  • 4
  • 14

1 Answers1

1

you can have a try like this: in the xml ,set "app:navigationIcon"(the left icon in the bottomAppBar):

   <android.support.design.bottomappbar.BottomAppBar
    android:id="@+id/bottom_appbar"
    android:layout_width="match_parent"
    android:layout_height="44dp"
    android:layout_gravity="bottom"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:fabAttached="true"
    app:backgroundTint="@color/colorPrimary"
    app:navigationIcon="@android:drawable/ic_dialog_email" 
    app:fabCradleVerticalOffset="12dp"/>

then in the activity:

  BottomAppBar bottomAppBar = (BottomAppBar) findViewById(R.id.bottom_appbar);
  bottomAppBar.setNavigationOnClickListener(this);

   @Override
   public void onClick(View v) {
    //do something
}
Leo Zhu
  • 15,726
  • 1
  • 7
  • 23
  • Thank you for the answer. I updated the image to show what I need. I want to add a badge in the navigation icon. The icon is already working, show a drawer. My problem is, that I need to add a notification badge on it. – DValdir Martins Dec 11 '18 at 22:13
  • @DValdirMartins Did you find a solution? – TruckerCat Jan 28 '21 at 20:56