Android setLayerType Webview

前端 未结 4 1495
抹茶落季
抹茶落季 2021-01-22 14:33

I am trying to create a WebView dynamically using the following code:

mWebView = new WebView(this);
mWebView.setId(R.id.webview);
mWebView.setVerticalScrollBarEn         


        
4条回答
  •  滥情空心
    2021-01-22 14:44

    below code works fine Android 3.0+ but when you try this code below android 3.0 then your app forcefully closed.

    webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
    

    You try below code on your less then API 11.

    webview.setBackgroundColor(Color.parseColor("#919191"));
    

    Or

    you can also try below code which works on all API fine.

    webview.setBackgroundColor(Color.parseColor("#919191"));
    if (Build.VERSION.SDK_INT >= 11) {
        webview.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
    }
    

    above code use full for me.

提交回复
热议问题