How to create an inbox style (with unread count) widget for android?

前端 未结 3 2027
借酒劲吻你
借酒劲吻你 2021-01-07 11:31

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

3条回答
  •  天涯浪人
    2021-01-07 12:36

    A widget like this is basically an standard RemoteViews implementation: http://developer.android.com/guide/topics/appwidgets/index.html is the guide for the widget. You need an XML layout that draws the icon as the widget background and overlay it with an image in the corner if the the count is greater than 0. You can use a TextEdit view with a background image and the number of images in the center of the background as the count.

    When you need to update it you can create a new RemoteViews instance from your layout file, set or hide the TextEdit based on the count and then call http://developer.android.com/reference/android/appwidget/AppWidgetManager.html#updateAppWidget%28int,%20android.widget.RemoteViews%29 to update the widget.

提交回复
热议问题