How to create custom widgets?

When using widget development for Android, it seems like you cannot add your own view classes to AppWidgetProvider.

For example, I created a custom class that extends the view, this works great when used in Activity, but the moment I add it to the widget, I get a “ClassNotFoundException” because Android seems to allow a set of specific system widgets to be added .

I saw some applications that look like they have their own custom widgets. For example, there is one that brings up a radial menu when clicked that shows application shortcuts. How are they implemented? Is there any work using my own widget? They seem to have a canvas that they can draw inside the widget.

Good quick example https://market.android.com/details?id=zombiesinthelab.widgets.droidpetwidget&feature=top-paid So, this widget is done by simply drawing the ImageViews and periodically updating them against using the canvas to draw frames?

+4
source share
2 answers

Android widgets can only contain widget layouts supported by RemoteViews . See this list :

The RemoteViews object (and therefore the 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 cannot change this behavior, it is hardcoded in android.

+7
source
+1
source

Source: https://habr.com/ru/post/1346530/


All Articles