Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 843
DeliveryNinja Avatar asked Feb 24 '23 15:02

DeliveryNinja


1 Answers

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.

like image 126
theomega Avatar answered Feb 27 '23 04:02

theomega