如何在Android汉堡菜单图标上实现徽章计数器 [英] How to implement a badge counter on android hamburger menu icon

查看:114
本文介绍了如何在Android汉堡菜单图标上实现徽章计数器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在汉堡菜单图标(即不是其他菜单图标)上设置计数器徽章.与eBay应用类似.就像..

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..

有人看过这个吗?试图找出最干净的方法.

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

推荐答案

使用Toolbar Widget非常简单,您可以按照以下示例来实现:

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

首先创建Oval shape

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

然后创建一个toolbar小部件,如下所示:

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>

这篇关于如何在Android汉堡菜单图标上实现徽章计数器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆