简体   繁体   中英

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&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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM