How do you make custom widgets?
When using developing Widgets for Android it seems you are not able to add your own custom View classes to a AppWidgetProvider.
For example I created a custom class which extends View, this works fine when used within an Activity but the moment I add it to a Widget I get a "ClassNotFoundException" because Android seems to only allow a set of certain system widgets to be added.
I have seen some apps which look like they have made there own custom widgets. For example there is one that brings up a radial menu when clicked which shows application shortcuts. How are these being implemented? Is there a work around to using my own custom widget? They seem to have a canvas which they are able to draw on within the widget.
Okay quick example https://market.android.com/details?id=zombiesinthelab.widgets.droidpetwidget&开发者_JAVA百科feature=top-paid So this widget is being done by just drawing ImageViews and updating them periodically opposed to using a canvas to draw the frames?
Android Widgets can only contain Layout-Widgets supported by RemoteViews. See this list:
A RemoteViews object (and, consequently, an App Widget) can support the following layout classes:
FrameLayout LinearLayout RelativeLayout
And the following widget classes:
AnalogClock Button Chronometer ImageButton ImageView ProgressBar TextView
> Descendants of these classes are not supported.
Pay attention to the last sentence. You can not change this behaviour, it is hard coded in android.
I have not much idea on how to create widgets but following links can definitely help you:
1) http://developer.android.com/guide/topics/appwidgets/index.html
2) http://developer.android.com/guide/practices/ui_guidelines/widget_design.html
精彩评论