如何创建一个收件箱风格(有未读邮件数)ANDROID小部件? [英] How to create an inbox style (with unread count) widget for android?

查看:182
本文介绍了如何创建一个收件箱风格(有未读邮件数)ANDROID小部件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个小部件为我的Andr​​oid应用程序。我想这是一个单细胞,但在右上角的注释。类似这显示在右上角的未读电子邮件/短信计数流行的小部件。这似乎是这将是常见的事,试图做,但我无法找到如何建立这种任何的例子。

I am trying to create a widget for my android app. I want it to be a single cell but with an annotation in the top right. Similar to popular widgets which display an unread email/sms count in the top right. This seems like it would be a common thing to try and do but I can't find any examples of how to build this.

我如何做到这一点?或者有什么资源都没有教我如何做到这一点?

How do I do this? Or what resources are there to teach me how to do this?

谢谢

罗宾

推荐答案

林不知道是否你是问如何建立一般Widget或只是小读指示。 有上了网,如何在一般建一个小部件的一些教程。例如: 这个或的官方文档

Im not sure whether you are asking how to build a widget in general or just for the small unread indication. There are some tutorials on the net, how to build a widget in general. For example: this one or the official documentation.

一旦你掌握了,小指示灯变成一个小问题,你就必须将其包含在你的布局。当更新窗口小部件,您只需更新的观点,即表示计数或设置它的知名度,无形的,当数为0。

Once you mastered that, the small indicator becomes a minor issue, you just have to include it in your layout. When updating the widget, you just update the view that indicates the count or set its visibility to invisible when the count is 0.

对于这种情况的一个例子布局将

An example layout for this case would be

  <FrameLayout> 
            <RelativeLayout> <ImageView /> </RelativeLayout>
            <RelativeLayout> <TextView /> </RelativeLayout>
  </FrameLayout>

下面的小部件由一个ImageView的,那你通常通过其周围RelativeLayout的中心。第二RelativeLayout的TextView的可以是未读的指标。 它的位置在角落里,就像您在RelativeLayout的风情吧。(通过机器人:背景=@可绘制/ my_indicator_background或类似的规定)

Here the widget consists of one ImageView, that you usually center via its surrounding RelativeLayout. The Textview in the second RelativeLayout can be your unread indicator. Position it in the corner like you would in a RelativeLayout and style it (via android:background="@drawable/my_indicator_background" or something along those lines).

和多数民众赞成它。 :)

And thats it. :)

这篇关于如何创建一个收件箱风格(有未读邮件数)ANDROID小部件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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