带徽章的 BottomAppBar 导航图标
BottomAppBar Navigation Icon with Badge
我正在应用程序中使用新的 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 class。但是在 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"/>
然后在 activity:
BottomAppBar bottomAppBar = (BottomAppBar) findViewById(R.id.bottom_appbar);
bottomAppBar.setNavigationOnClickListener(this);
@Override
public void onClick(View v) {
//do something
}
我正在应用程序中使用新的 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 class。但是在 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"/>
然后在 activity:
BottomAppBar bottomAppBar = (BottomAppBar) findViewById(R.id.bottom_appbar);
bottomAppBar.setNavigationOnClickListener(this);
@Override
public void onClick(View v) {
//do something
}