Notification Badge On Action Item Android

后端 未结 6 1070
感动是毒
感动是毒 2020-12-04 06:06

I wana add a notification badge on the cart image placed in action bar and manipulate it programmatically. Any Help?

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-04 06:47

    Using https://github.com/nikartm/Image-Support that will take care of creating the badge with more options like max count limit, etc.

    layout_menu_cart.xml

    
    
    
        
    
    
    

    main_menu.xml

    
    
        
    
    

    YourActivity.kt

    val menuItem = menu.findItem(R.id.menu_cart) as MenuItem
    val actionView = menuItem.actionView
    
    actionView.findViewById(R.id.cart_menu_icon).badgeValue = count
    

提交回复
热议问题