Android 中像 iPhone 一样的绘图编号徽章 [英] Drawing number badge like iPhone in Android

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

问题描述

我想在聊天选项卡上绘制如上图所示的数字徽章.该数字徽章显示聊天中新的未读消息的数量.那么我如何绘制这种自定义数字徽章.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.

推荐答案

看我的回答 此处 用于小部件/应用程序.

Look at my answer here for widgets/app.

你可以使用shapecount.xml

res/layout/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

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

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