【发布时间】:2011-05-18 12:43:36
【问题描述】:
我想在“聊天”选项卡上绘制如上图所示的数字徽章。该数字徽章显示聊天中新的未读消息的数量。那么我该如何绘制这种自定义数字徽章。 Android SDK中是否有任何内置API?提前致谢。
【问题讨论】:
我想在“聊天”选项卡上绘制如上图所示的数字徽章。该数字徽章显示聊天中新的未读消息的数量。那么我该如何绘制这种自定义数字徽章。 Android SDK中是否有任何内置API?提前致谢。
【问题讨论】:
查看我的回答 here 获取小部件/应用程序。
你可以使用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 的示例来对此进行测试。
您还必须根据需要安排布局
【讨论】:
您可以通过使用 FrameLayout 来实现这一点:Common Layout Objects
【讨论】:
有一个方便的library 可以轻松实现这一点。只需一个 jar 文件即可添加到您的项目中。
【讨论】: