Adding badges to Bottom navigation and not able to reference the getOrCreateBadge(正在向底部导航添加徽章,并且无法引用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本身添加菜单项:仍然没有效果
- 改主题为材料主题:仍然是同一期
- 使用底部导航活动创建了一个单独的项目:如果我添加徽章,该项目中没有问题。我也把它的主题改成了我的应用程序主题,也就是说,App compat仍然可以在该项目中使用徽章。
- 最初Android素材没有添加依赖项,我可以使用底部导航栏。但由于我在添加徽章时遇到了问题,所以我在外部添加了依赖性,并确保将最新版本也放在最后,但仍然面临同样的问题。无法在底部导航中添加徽章。
我知道这是很基本的东西,但如果有人能指出这一点,那将是一个很大的帮助,因为这个问题已经在过去两天里被困住了。提前感谢。
推荐答案
理想情况下,应该使用实现‘com.google.android.Material:Material:1.3.0’。确保在Gradle同步和重建之前删除了Builds文件夹。
这篇关于正在向底部导航添加徽章,并且无法引用getOrCreateBadge的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!