首页 > 解决方案 > 带有徽章的 BottomAppBar 导航图标

问题描述

我在应用程序中使用新的 BottomAppBar。但我无法让徽章工作。我尝试使用BottomNavigationView上使用的相同逻辑,但它不起作用。(在另一个应用程序中,我在BottomAppBar中有一个BottomNavigationView,其中徽章工作,但无法在BottomAppBar应用程序(导航图标)中使用相同的代码。

   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);

我想做的事: 在此处输入图像描述

我尝试了 BadgeNavigationDrawable 类。但在 BottomAppBar 中找不到对导航图标的正确引用。

谢谢。

标签: androidandroid-studioandroid-bottomappbar

解决方案


你可以试试这样:在xml中,设置“app:navigationIcon”(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"/>

然后在活动中:

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

   @Override
   public void onClick(View v) {
    //do something
}

推荐阅读