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

前端 未结 3 2105
借酒劲吻你
借酒劲吻你 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:12

    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. :)

提交回复
热议问题