Android webview 快照及白屏闪屏解决方案

来源:互联网 发布:windows应用商店误删 编辑:程序博客网 时间:2024/06/05 20:02

快照方法:

 /**      * 截取webView可视区域的截图      * @param webView 前提:WebView要设置webView.setDrawingCacheEnabled(true);      * @return      */  private Bitmap captureWebViewVisibleSize(WebView webView){      Bitmap bmp = webView.getDrawingCache();      return bmp;  } /**   * 截取webView快照(webView加载的整个内容的大小)   * @param webView   * @return   */  private Bitmap captureWebView(WebView webView){      Picture snapShot = webView.capturePicture();      Bitmap bmp = Bitmap.createBitmap(snapShot.getWidth(),snapShot.getHeight(), Bitmap.Config.ARGB_8888);      Canvas canvas = new Canvas(bmp);      snapShot.draw(canvas);      return bmp;  }  /**   * 截屏   * @param context   * @return   */     private Bitmap captureScreen(Activity context){       View cv = context.getWindow().getDecorView();       Bitmap bmp = Bitmap.createBitmap(cv.getWidth(), cv.getHeight(),Config.ARGB_8888);       Canvas canvas = new Canvas(bmp);       cv.draw(canvas);       return bmp;  

前提:WebView要设置webView.setDrawingCacheEnabled(true);
第一种效果还可以。其他待测,截屏的尽量不要弄,容易出问题。

白屏和闪屏解决

1.在WebView的xml属性中设置Android:layerType=software
取消硬件加速法

2.在代码中设置背景透明setBackgroundColor(0);
背景透明发

3.快照影响或其他view影响
当有快照的时候,排查是否为快照的白色页面,还有在设置view.setVisibility();时,如果用隐藏(INVISIBLE)或(GONE),没效果,可以换个角度,处理显示的,让显示的显示(VISIBLE),这样也是可以的。

1 0
原创粉丝点击