AppWidget image with rounded corners

旧街凉风 提交于 2019-12-02 08:12:59

Sadly, AppWidgets are quite limited in terms of views. you can only use the views that Android supports.

The reason is that the code of the view needs to run on the container of the AppWidget, and that's a security risk, since you could get a glimpse at the private data of the app that shows it. So what Google did is that you need to prepare what to show, and when you finished, tell a restricted API how to show the AppWidget.

So the solution would be to flush the image as it should be shown , to an imageView or something similar. I suggest to do it in the background if it has a lot to prepare.

It all depends on your needs.

In addition to this issue:

'It turns out that the size of my AppWidget was clipping the image the whole time. Clipping it just enough to remove the rounded corners, and just so little as to not have been obviously clipped. So for anyone that comes across this question... all of these method's work for this purpose (just don't forget to make your AppWidget big enough to see the results).'

Answer:

I found it was critical to also pass the RoundedCornersDrawable through the CustomView.drawToBitMap() method before exporting it to the PNG file.

I hope this all helps someone down the road someday!

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