Dynamically adding a View to an android widget

旧城冷巷雨未停 提交于 2019-12-05 10:03:56
Programmer Bruce

It's not possible to add a custom View to an app widget. See the "Creating the App Widget Layout" section of the App Widgets Dev Guide for what View types are allowed.

Android 3.0 adds support for some views to display collections. See the "Using App Widgets with Collections" section for details.

Otherwise, to dynamically add an allowed View to an App Widget, after inflating the RemoteViews and getting a reference to it, you can use its addView(View) method, or the addView(View) method on any of the View objects already in the RemoteViews.

As Bruce correctly answered, it is not possible to use a custom view. Since it seems like your view doesn't respond to input, and just draws, you can achieve the same functionality with an ImageView. Just create a Bitmap, create a Canvas with it, and then draw on it using what was your onDraw code. Then create an ImageView (which is allowed in a widget) and set the image it displays to your Bitmap.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!