Android: Use Webview For Wallpaperservice
TL;DR: I'm making a live wallpaper using WallpaperService, and I want to draw to it from a WebView. However, when I create the WebView, it's 0 width and height, so nothing draws bu
Solution 1:
Okay, I've got it working, thanks to some help on Reddit. So ultimately you need to create a WebView but not try to attach it to anything. Then you have to size it so it shows content; that was the last missing piece. Here's the code for that:
// Get the screen width and height and put them in screenWidth and screenWidth // and then do the following with them:int widthSpec = View.MeasureSpec.makeMeasureSpec(screenWidth, View.MeasureSpec.EXACTLY);
int heightSpec = View.MeasureSpec.makeMeasureSpec(screenHeight, View.MeasureSpec.EXACTLY);
webView.measure(widthSpec, heightSpec);
webView.layout(0, 0, screenWidth, screenHeight);
Then you can draw from the WebView to the SurfaceHolder's Canvas and everything is lovely.
Thank you all for the help!
UPDATE 11 MAR 2019
It's all working now, so I thought I'd share a Gist of the code in case it's useful to other people:
https://gist.github.com/iangilman/71650d46384a2d4ae6387f2d4087cc37
Post a Comment for "Android: Use Webview For Wallpaperservice"