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