在为 Android 使用开发小部件时,您似乎无法将自己的自定义 View 类添加到 AppWidgetProvider。
例如,我创建了一个扩展 View 的自定义类,这在 Activity 中使用时工作正常,但当我将它添加到 Widget 时,我得到一个“ClassNotFoundException”,因为 Android 似乎只允许一组特定的系统小部件被添加。
我看到一些应用程序看起来像是在其中制作了自己的自定义小部件。例如,有一个在单击时会弹出一个显示应用程序快捷方式的径向菜单。这些是如何实现的?是否可以使用我自己的自定义小部件?他们似乎有一 block Canvas ,可以在小部件内绘图。
好的快速示例 https://market.android.com/details?id=zombiesinthelab.widgets.droidpetwidget&feature=top-paid 所以这个小部件是通过绘制 ImageView 并定期更新它们而不是使用 Canvas 绘制框架来完成的?
最佳答案
Android Widgets 只能包含 RemoteViews 支持的 Layout-Widgets .参见 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.
注意最后一句话。您无法更改此行为,它在 android 中进行了硬编码。
关于java - 你如何制作自定义小部件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5536595/