公共类MainActivity扩展了Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText editText = (EditText)findViewById(R.id.textView);
View view = findViewById(R.id.button);
final WebView webView = (WebView)findViewById(R.id.webView);
webView.setWebViewClient(new MyBrowser());
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String url = editText.getText().toString();
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadsImagesAutomatically(true);
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webView.loadUrl(url);
}
});
}
private class MyBrowser extends WebViewClient{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}
错误状态 得到错误为“不允许加载本地资源:file:///android_asset/webkit/android-weberror.png”,来源:data:text / html,chromewebdata(12)“