How to implement a badge counter on android hamburger menu icon [duplicate]

倾然丶 夕夏残阳落幕 提交于 2019-12-04 12:06:23

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>

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!