question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BottomNavigationView - can't use getOrCreateBadge with AppCompat theme

See original GitHub issue

Why we can’t use BottomNavigationView widget counter badge functionality with AppCompat theme?

image

App build.gradle:

image

And crash error when trying call to method getOrCreateBadge:

  --------- beginning of crash
2019-11-01 17:04:08.199 27162-27162/com.example E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example, PID: 27162
    java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
        at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:243)
        at com.google.android.material.internal.ThemeEnforcement.checkMaterialTheme(ThemeEnforcement.java:217)
        at com.google.android.material.badge.BadgeDrawable.<init>(BadgeDrawable.java:379)
        at com.google.android.material.badge.BadgeDrawable.createFromAttributes(BadgeDrawable.java:305)
        at com.google.android.material.badge.BadgeDrawable.create(BadgeDrawable.java:273)
        at com.google.android.material.bottomnavigation.BottomNavigationMenuView.getOrCreateBadge(BottomNavigationMenuView.java:641)
        at com.google.android.material.bottomnavigation.BottomNavigationView.getOrCreateBadge(BottomNavigationView.java:673)
        at com.example.MainActivity$onCreate$1.onPropertyChanged(MainActivity.kt:75)
        at androidx.databinding.PropertyChangeRegistry$1.onNotifyCallback(PropertyChangeRegistry.java:30)
        at androidx.databinding.PropertyChangeRegistry$1.onNotifyCallback(PropertyChangeRegistry.java:26)
        at androidx.databinding.CallbackRegistry.notifyCallbacks(CallbackRegistry.java:201)
        at androidx.databinding.CallbackRegistry.notifyFirst64(CallbackRegistry.java:122)
        at androidx.databinding.CallbackRegistry.notifyRemainder(CallbackRegistry.java:169)
        at androidx.databinding.CallbackRegistry.notifyRecurse(CallbackRegistry.java:145)
        at androidx.databinding.CallbackRegistry.notifyCallbacks(CallbackRegistry.java:91)
        at androidx.databinding.BaseObservable.notifyChange(BaseObservable.java:60)
        at androidx.databinding.ObservableInt.set(ObservableInt.java:89)
        at com.example.viewmodels.AppModel.addToBasket(AppModel.java:120)
        at com.example.viewmodels.AppModel.addToBasket(AppModel.java:125)
        at com.example.fragments.products.ShowProductDetailsBottomSheet$initListeners$$inlined$let$lambda$4.onClick(ShowProductDetailsBottomSheet.kt:386)
        at android.view.View.performClick(View.java:7125)
        at android.view.View.performClickInternal(View.java:7102)
        at android.view.View.access$3500(View.java:801)
        at android.view.View$PerformClick.run(View.java:27336)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

11reactions
summerEndcommented, Jan 13, 2020

<com.google.android.material.bottomnavigation.BottomNavigationView android:id=“@+id/bottomNavigation” app:theme=“@style/Theme.MaterialComponents” style=“@style/AppWidget.BottomNavigation” app:layout_constraintBottom_toBottomOf=“parent” app:layout_constraintStart_toStartOf=“parent” app:menu=“@menu/bottom_tab_menu” /> @boyfox

0reactions
Jitendrancommented, Aug 27, 2020

Please increase the version number. And after that I faced 1 more issue. java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant). To resolved this issue I used below lines. app:theme=“@style/Theme.MaterialComponents” style=“@style/Widget.Design.BottomNavigationView”

Thanks summerEnd.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding badges to Bottom navigation and not able to reference ...
I am trying to add badges in bottom navigation but the problem is getOrCreateBadge is not getting referenced. I am unable to access...
Read more >
BottomNavigationView - Android Developers
Represents a standard bottom navigation bar for application. It is an implementation of material design bottom navigation.
Read more >
Adding badges to Bottom navigation - Android - CodeRanch
Hello, I am trying to add badges in bottom navigation but the problem but getOrCreateBadge is not getting referenced. I am unable to...
Read more >
Android BottomNavigationView Using Kotlin With Example
Learn android BottomNavigationView Using Kotlin with example, show or hide icon, set custom style, ripple in bottomNavigationView in Kotlin.
Read more >
NavigationRailView MaterialDesign 1.4.0 Stable - Droidcon
Portrait mode : Application will use BottomNavigationView ... import androidx.appcompat.app. ... getOrCreateBadge(R.id.alarms).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found