就像iPhone在Android的图号徽章 [英] Drawing number badge like iPhone in Android

查看:123
本文介绍了就像iPhone在Android的图号徽章的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个繁忙的猫

我想提请数章,以显示在聊天选项卡上面的图片。这个数字徽章显示在聊天新的未读邮件数。所以,我怎么可以得出这样的自定义数字徽章。有没有在Android SDK中的任何内置的API?提前致谢。

I want to draw the number badge as shown in the above image on the Chats tab. That number badge shows number of new unread messages in chat. So how can I draw this kind of custom number badge. Is there any inbuilt API in Android SDK? Thanks in advance.

推荐答案

看我的答案<一href="http://stackoverflow.com/questions/5569695/android-is-it-possible-to-update-a-imageview-imagebutton-with-a-number-to-show-t/5604787#5604787">here对于小部件/应用程序。

Look at my answer here for widgets/app.

您可以使用 shapecount.xml

RES /布局/ tabicon.xml

<RelativeLayout
    android:orientation="vertical"
    android:background="@null"
    android:id="@+id/rlayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
    <ImageView 
            android:id="@+id/icon"
            android:src="@android:drawable/ic_menu_mylocation" <!-- Just for test -->
            android:layout_margin="0dp"
            android:layout_height="wrap_content" 
            android:layout_width="wrap_content"/>

    <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:text="50" android:textSize="12dp" android:textStyle="bold"  
        android:background="@drawable/shapecount"
        android:textColor="#FFFFFF"
        android:paddingLeft="3dp" android:paddingRight="3dp"
            android:layout_margin="0dp"
        android:layout_alignBottom="@+id/rlayout"
        android:id="@+id/txtCount" />

</RelativeLayout>

在创建标签:

LayoutInflater inflater = LayoutInflater.from(this);
View view = inflater.inflate(R.layout.tabicon, null);
final TextView txtCount = (TextView) view.findViewById(R.id.txtCount);

spec = tabHost.newTabSpec("artists").setIndicator(view).setContent(intent);

现在,您可以使用 txtCount 更新标签的图标的数量。见我指出了上述的TimerTask的例子后进行测试。

Now you can use txtCount to update the number in the tab's icon. See the post I pointed out above for an example of TimerTask to test this.

您必须安排布局,如你所愿也。

You will have to arrange the layout as you wish also

这篇关于就像iPhone在Android的图号徽章的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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