Native Shopify Mobile App with 20 new features
Kickstart your hyperlocal marketplace in Corona pandemic with a starter guide
Android App Development
iOS App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 18.104.22.168 release ready!
Owner and Founder. Opencart
In every application, we decorate our MenuItem placed on ActionBar. Displaying of badge count not only decorate the ActionBar beautifully but also displays useful information like showing the number of items currently available in your cart or update you with unread notification.
We can create badge count using either a custom view or by adding a distinct drawable to display the each state of MenuItem.
Both the options have its pros and cons.
There is another approach using LayerDrawable which is more flexible and efficient than the former approaches.
A Drawable that manages an array of other Drawables. These are drawn in array order, so the element with the largest index will be drawn on top.It can be defined in an XML file with the
It can be defined in an XML file with the <layer-list> element. Each Drawable in the layer is defined in a nested<item>
i. Creating a layer drawable to display menu item on layer one and badge on top of it.
ii. Creating menu for our activity to display the count on the menu items.
iii. Creating a flexible and efficient custom BagdeDrawable class to draw a view that looks like a count
We can get the icon of the menu using getIcon() method.
Here is our method setBadgeCount(). We can pass LayerDrawable which we get from meniItem and setBadge from anywhere from the application.
Your email address will not be published. Required fields are marked*
Save my name email and website in this browser for the next time I comment.
This will set mWillDraw to false if the count is “0”. Thus This will not draw the badge or simply remove the badge.
here if I get reuse as null;the onDraw() method of BadgeDrawable is not called at all(so no badge) since the bounds are 0; how do I fix this; sometimes badge will get drawn as sometimes not and it entirely depends on reuse variable (if its null no badge and if its not null, I can see the badge).
Thanks, any help will be greatly appreciated 😉
Getting the above ClassCastException
MenuInflater inflater = getMenuInflater();
MenuItem itemCart = menu.findItem(R.id.action_cart);
LayerDrawable icon = (LayerDrawable)itemCart.getIcon();
setBadgeCount(this, icon, “9”);
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.