在运行时从另一个应用程序获取自定义视图
我正在努力思考从另一个应用程序获取 CustomView
的想法。假设我有两个应用程序 A 和 B。我知道 CustomView
的包名称,例如 com.applicationb.CustomView
。是否可以在运行时在应用程序 A 中创建此类的对象?
我的目标是找到一种创建 CustomViews 并能够在我的应用程序中显示它们的方法。但我希望它们(视图)成为一个单独的 apk,可以发布到 Android Market,并作为某种扩展下载。
CustomView
只会在屏幕上显示某种动画(例如落叶)。它不适用于第一次应用程序中的任何数据。
编辑
我发现了这样的东西:
@SuppressWarnings("rawtypes")
Class c = Class.forName(package_name);
Method m = c.getDeclaredMethod(method_name);
m.setAccessible(true);
Canvas can= (Canvas) m.invoke(null, null); // since there are no parameters, and called function is static
我希望这会起作用。我让你知道了。
I am struggling with the idea of getting CustomView
from another application. Lets say I have two applications A and B. I know package name of CustomView
, for example com.applicationb.CustomView
. Is it possible to create an Object of this Class in application A at runtime?
My aim is to find a way to create CustomViews
and being able to show them in my application. But I want them (views) to be a separate apk, which may be published to Android Market, and downloaded as some kind of extension.
CustomView
would only display somekind of animation on screen (for example falling leaves). It would not work on any data in first application.
Edit
I found something like this:
@SuppressWarnings("rawtypes")
Class c = Class.forName(package_name);
Method m = c.getDeclaredMethod(method_name);
m.setAccessible(true);
Canvas can= (Canvas) m.invoke(null, null); // since there are no parameters, and called function is static
I hope this will work. I let you know.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如我在这里所承诺的那样,这是结果。
使用此代码,可以使用应用程序 A 从应用程序 B 获取视图。
As I promissed here is result.
With this code it is possible to get View from application B from using application A.