2011-03-25 117 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); 

} 

希望它能帮助,如果你需要更多的信息请随时询问。