gpt4 book ai didi

java - 你如何制作自定义小部件?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:07:15 24 4
gpt4 key购买 nike

在为 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com