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?
Thanks,
Robin
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.
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
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. 🙂