简体   繁体   English

Android:在我自己的应用程序中显示小部件的预览

[英]Android: displaying a preview of widget in my own app

I'm creating an App that has a homescreen widget, and I'd like to have it so the user can see a live preview of what the widget will look like, within my actual App activity, when they're configuring settings for the widget.我正在创建一个具有主屏幕小部件的应用程序,我希望拥有它,以便用户可以在我的实际应用程序活动中看到小部件外观的实时预览,当他们为小部件。 I recently downloaded an app that did that exact thing, and it seemed like a great feature.我最近下载了一个可以做到这一点的应用程序,这似乎是一个很棒的功能。

Any idea how I'd go about accomplishing this?知道我如何 go 来完成这个吗? I found some references to AppWidgetHostView , is that what I need?我发现了一些对AppWidgetHostView的引用,这是我需要的吗?

I'm very new to Android development (as in just started the tutorials today), so bear with me if this question is missing anything important!我对 Android 开发非常陌生(就像今天刚刚开始的教程一样),所以如果这个问题缺少任何重要的东西,请多多包涵!

I found some references to AppWidgetHostView, is that what I need?我发现了一些对 AppWidgetHostView 的引用,这是我需要的吗?

AppWidgetHostView is one option. AppWidgetHostView是一种选择。 I think you can put that in your layout and call updateAppWidget() on it, supplying your RemoteViews .我认为你可以把它放在你的布局中并调用updateAppWidget() ,提供你的RemoteViews

Or, your activity/fragment can call apply() on the RemoteViews to have that UI poured into some ViewGroup (eg, a FrameLayout ).或者,您的活动/片段可以RemoteViews上调用apply()以将该 UI 倒入某个ViewGroup (例如FrameLayout )。

In either case, you would need your function that creates your RemoteViews to be available to both your AppWidgetProvider and your activity/fragment that implements your preview.在任何一种情况下,您都需要您的 function 来创建您的RemoteViews ,以便您的AppWidgetProvider和实现预览的活动/片段都可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM