android - 带有徽章的 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 中找不到对导航图标的正确引用。
谢谢。
解决方案
你可以试试这样:在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
}
推荐阅读
- javascript - CSS - 如何内联表单/输入但使用适当的缩进堆叠每一行?
- php - 借助 AJAX,如何通过请求 PHP 文件来更改文本值?(不刷新页面)
- vb.net - vb.net 如何获得使用 htmlagilitypack的价值
- cloud-foundry - 了解 manifest.yml 关键云代工中的以下环境条目
- css - Flex-wrap 不包裹 IE11 中的项目
- python - django使用gridfs上传图片
- c# - 如何将数据从复选框 (html) 导入数据库 ASP.NET Core MVC
- python - Django 装饰器 - 重新输入密码以继续
- amazon-web-services - 如何在 AWS Cloudsearch 中执行包含符号的结构化查询
- wolfram-mathematica - 恢复笔记本 Mathematica