3

我正试图在汉堡包菜单图标(即不是其他菜单图标)上实施一个计数器徽章。类似于eBay应用程序。作为..如何在Android汉堡包菜单图标上实现徽章计数器

Ebay app badge counter

有没有人研究过这?试图弄清楚最干净的方式。

+1

ya在菜单图标图像上方设置textview并设置圆形背景 – Destro

+1

您是否可以将汉堡包菜单图标嵌入为主题的一部分,从而可以精心制作菜单图标?那么你如何改变它? – FlashAsh99

+2

这与在汉堡包菜单图标上专门添加徽章并不重复。不是其他菜单图标 – FlashAsh99

回答

6

它相当简单与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> 

enter image description here

+0

我最终删除了现有的菜单图标,并使用上述布局设置了徽章。谢谢 – FlashAsh99

+0

@ k0sh你可否详细说明一下。我已经尝试过你的代码,并且最后只有两个汉堡包图标: -/ –

+0

@ ban-geoengineering如果使用上述代码,请删除编程设置的汉堡包图标。 – k0sh