3

I am trying to implement a counter badge on the hamburger menu icon (i.e. not the other menu icons). Similar to the eBay app. as in..

Ebay app badge counter

Has anyone looked into this? Trying to figure out the cleanest way possible.

FlashAsh80
  • 1,357
  • 1
  • 16
  • 27

1 Answers1

7

its pretty simple to do with the Toolbar Widget you could follow below example to achieve that:

first create an Oval shape

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid android:color="#ff00"/>
</shape>

then create a toolbar widget as below:

<android.support.v7.widget.Toolbar
    android:layout_width="match_parent"
    android:layout_height="?actionBarSize"
    android:background="?colorPrimary">

    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent">

        <ImageView
            android:id="@+id/openMenu"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/ic_menu"/>

        <TextView
            android:id="@+id/badger"
            android:layout_width="16dp"
            android:layout_height="16dp"
            android:layout_gravity="end|right|top"
            android:layout_marginTop="10dp"
            android:background="@drawable/badge"
            android:gravity="center"
            android:text="1"
            android:textColor="@color/white"/>

    </FrameLayout>
</android.support.v7.widget.Toolbar>

enter image description here

Kosh
  • 6,140
  • 3
  • 36
  • 67