这是WebViewActivity
的代码,用于加载WebView
。我尝试了以下代码。
public class WebviewActivity extends Activity {
WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview);
webView = (WebView) findViewById(R.id.webview);
setupWebView();
webView.loadUrl("http://www.Example.com/");
}
private void setupWebView() {
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
webView.loadUrl("javascript:MyApp.resize(document.body.getBoundingClientRect().height)");
super.onPageFinished(view, url);
}
});
webView.addJavascriptInterface(this, "MyApp");
}
@JavascriptInterface
public void resize(final float height) {
WebviewActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
webView.setLayoutParams(new RelativeLayout.LayoutParams(getResources().getDisplayMetrics().widthPixels, (int) (height * getResources().getDisplayMetrics().density)));
}
});
}
}
加载
WebView
时出现错误libEGL: validate_display:255 error 3008 (EGL_BAD_DISPLAY)
最佳答案
尝试使用WebChromeClient(导入android.webkit.WebChromeClient;),而不是WebViewClient
关于android - libEGL:加载WebView时validate_display:255错误3008(EGL_BAD_DISPLAY),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50362747/