android - 将徽章添加到底部导航并且无法引用 getOrCreateBadge
问题描述
我正在尝试在底部导航中添加徽章,但问题是 getOrCreateBadge 没有被引用。我无法访问此方法。
错误:未解决的参考:getOrCreateBadge
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment_container"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bnv_nav"
app:defaultNavHost="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bnv_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/dp56"
android:layout_alignParentBottom="true"
android:fitsSystemWindows="true"
app:itemIconTint="@drawable/tab_color"
app:itemTextColor="@drawable/tab_color" />
主题
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">@color/white</item>
<item name="android:textViewStyle">@style/AppTheme.Widget.TextView</item>
<item name="android:actionBarStyle">@style/AppTheme.ActionBar</item>
<item name="android:navigationBarColor" tools:targetApi="21">@color/white</item>
<item name="android:windowLightNavigationBar" tools:targetApi="27">true</item>
<item name="android:windowDisablePreview">true</item>
</style>
我在运行时添加菜单项。
我已经尝试过的事情:
- 从 xml 本身添加菜单项:仍然没有效果
- 将主题更改为材料主题:仍然是同样的问题
- 使用底部导航活动创建了一个单独的项目:如果我添加徽章,该项目中没有问题。我也将它的主题更改为我的应用程序主题,即应用程序兼容仍然徽章在该项目中运行良好。
- 最初没有添加android材料的依赖,我可以使用底部导航栏。但是由于我在添加徽章时遇到了问题,所以我在外部添加了依赖项,并确保也放入最新版本,但最终仍然面临同样的问题。无法在底部导航中添加徽章。
我知道这是非常基本的事情,但如果有人能指出这将是一个很大的帮助,这将是一个很大的帮助,从过去两天开始就已经解决了这个问题。预先感谢。
解决方案
理想情况下,您应该使用实现 'com.google.android.material:material:1.3.0' 。确保在 gradle 同步和重建之前删除 builds 文件夹。
推荐阅读
- mysql - 尝试配置 CartoDB 时无法使用 db:create
- c# - 使用 C# 删除 Windows 用户(远程)
- javascript - 使用另一个 json 对象从 json 对象中删除特定内容
- three.js - 使用 InstancedBufferGeometry 时未定义索引
- javascript - 如何让particle.js 只移动一个特定的div?
- html - CSS:计算两个重叠矩形在旋转后的溢出
- c++ - 我可以安全地混合使用 -std=c++11 和 -std=c++14 编译的库吗?
- cmake - CMake 将项目文件夹移动到另一台计算机
- php - 在模型 PHP CI 中获取结果搜索
- python - 从字符串中获取特定信息