我尝试使用WebView显示Google地图网页。如果我使用的目标网址类似于' http://www.google.co.uk'或者' http://www.youtube.com' webview有效,但不是在我使用' http://www.google.co.uk/maps/dir//NEC,+North+Avenue,+Birmingham/'
时WebView无法使用地图网址并显示空白框
Java类:
public class location_Fragment extends Fragment {
private WebView webView;
View rootview;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootview = inflater.inflate(R.layout.location_layout, container, false);
webView = (WebView)rootview.findViewById(R.id.webView);
webView.setWebViewClient(new MyBrowser());
WebSettings webSettings = webView.getSettings();
webSettings.setBuiltInZoomControls(true);
webSettings.setJavaScriptEnabled(true);
webView.loadUrl("http://www.google.co.uk/maps/dir//NEC,+North+Avenue,+Birmingham/");
return rootview;
}
private class MyBrowser extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}
的AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package= ... >
<uses-permission android:name="android.permission.INTERNET" />
<application ...
</application>
</manifest>