如何在 android 汉堡菜单图标上实现徽章计数器
How to implement a badge counter on android hamburger menu icon
我正在尝试在汉堡包菜单图标(即不是其他菜单图标)上实现一个计数器徽章。类似于 eBay 应用程序。如..
有人调查过这个吗?试图找出最干净的方法。
使用 Toolbar Widget
非常简单,您可以按照以下示例来实现:
先创建一个Oval shape
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#ff00"/>
</shape>
然后创建一个 toolbar
小部件,如下所示:
<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>
我正在尝试在汉堡包菜单图标(即不是其他菜单图标)上实现一个计数器徽章。类似于 eBay 应用程序。如..
有人调查过这个吗?试图找出最干净的方法。
使用 Toolbar Widget
非常简单,您可以按照以下示例来实现:
先创建一个Oval shape
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#ff00"/>
</shape>
然后创建一个 toolbar
小部件,如下所示:
<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>