What's the proper way to implement an Android widget with dynamically drawn content?

后端 未结 3 1200
Happy的楠姐
Happy的楠姐 2020-12-29 08:11

For my first and most awesomest Android project, I want to create a home screen widget which displays one of those Arc Clocks that all the kids are raving about these days.<

3条回答
  •  孤独总比滥情好
    2020-12-29 08:52

    There is actually a widget called AnalogClock in the SDK that is very similar to what you are trying to do.

    It is implemented as a class that extends View and is annotated with @RemoteView. It registers receivers on Intent.ACTION_TIME_TICK and Intent.ACTION_TIME_CHANGED and draws itself by overriding the onDraw method. Check out the source. The standard AlarmClock application exposes this view as a widget that can be added to the home screen.

    I think that is a good (if not the best) way to implement what you described and obviously works well.

提交回复
热议问题