2011-03-25 116 views
0

是否有任何可能性在Android標籤欄中添加通知,如iPhone標籤中的徽章。我不是指通知。這裏我會將iPhone徽章屏幕截圖也放在這裏。 enter image description here安卓標籤欄

如果徽章在android中不可用,是在標籤欄前放置一個視圖一個很好的解決方案?

+4

也許你以前的一些問題有答案,你可以接受? – Nanne 2011-03-25 14:07:47

+0

這是很容易做在Android只是檢查我的答案http://stackoverflow.com/a/16359798/1939564 – 2013-05-07 07:36:19

回答

1

無法在選項卡上添加徽章或小視圖。 但是,您可以創建自定義選項卡,並在每個視圖中添加這些選項卡,在每個活動中重寫setContentView(),並在設置內容視圖之前處理您的自定義選項卡。

2

這樣做的可能方法是在您的Android項目中包含android-viewbadger.jar,然後使用BadgeView對象。

0

您可以創建自定義選項卡項目xml,並將RelativeLayout與背景圖像和centerInParent textView放在一起。將RelativeLayout的可見性設置爲GONE,並且只要您想顯示它,將其設置爲可見並將該Textview設置爲您想要的任何文本。

<RelativeLayout 
     android:id="@+id/tabBadge" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="47dp" 
     android:layout_marginTop="10dp" 
     android:layout_toStartOf="@+id/tabTitle" 
     android:visibility="gone" > 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:background="@drawable/basket_item" 
      android:contentDescription="@string/action_settings" /> 

     <TextView 
      android:layout_centerInParent="true" 
      android:id="@+id/tabBadgeText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:textColor="#ffffff" 
      android:textSize="10sp" /> 
    </RelativeLayout> 

同時一定要設置RelativeLayout的在你的代碼,而你正在生成的標籤像下面的代碼,所以你可以只要你想獲得它:

// mTitle is the title of the tab 

if (mTitle.equalsIgnoreCase("Basket")) { 

//count is the TextView inside your badge 

count = (TextView) view.findViewById(R.id.tabBadgeText); 

//layout is the whole badge's layout 

layout = (RelativeLayout) view.findViewById(R.id.tabBadge); 

} 

希望它能幫助,如果你需要更多的信息請隨時詢問。