ProgressBar in an AppWidget

2019-03-28 06:06发布

I ran into an interesting situation with using a ProgressBar in an App Widget... The documentation (http://developer.android.com/guide/topics/appwidgets/index.html) says that ProgressBar is a supported widget class...

I have no problem getting the ProgressBar to display in my App Widget but the problem is that I want it to only be displayed as visual feedback to the user when background processing is happening.

On ImageViews I do this via RemoteViews.setViewVisibility() and everything works fine. However, with ProgressBar I get an exception saying that ProgressBar can't use this method.

Is this intentional or is this a bug? Is there any way to workaround this problem?

2条回答
祖国的老花朵
2楼-- · 2019-03-28 06:31

An even simpler idea, is to put the progress bar inside some container (say a linear layout) and show/hide the container.

查看更多
Ridiculous、
3楼-- · 2019-03-28 06:36

It might be a bug. There's a particular annotation (@RemotableViewMethod) you need in the Java source code of Android itself to mark a method as being available via RemoteViews. View has this for setVisibility(), but ProgressBar overrides that method and does not have the annotation on its own edition. If @RemotableViewMethod is not inherited, and the override "undoes" the annotation, that would explain the symptom you see.

A workaround is to use two app widget layouts and choose the one you want (with or without ProgressBar) when you create your RemoteViews object when updating your app widget.

I'll make a note to try to replicate this and, if I see the same thing, I'll post an issue on it on the Android issue tracker.

查看更多
登录 后发表回答