我有一个有viewpager和一个按钮的活动。点击按钮移动到OutletMapWebView活动,各自需要参数(viewpager数据),下面是
的代码protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pd = (Integer.parseInt(android.os.Build.VERSION.SDK) < 11)? new ProgressDialog(MainActivity.this) : new ProgressDialog(MainActivity.this, android.R.style.Theme_Holo_Panel);
webView = (WebView) findViewById(R.id.outletMapWebView);
// String MAP_URL = "<html><body><iframe width='100%' height='100%' frameborder='0' style='border:0' src='https://www.google.com/maps/embed/v1/directions?key=AIzaSyD7mjSU3lSzYHgGcUglDog9cxLNjZDq_68&origin=12.9312987,77.5154981&destination=217 East Coast Road, Singapore&mode=driving'></iframe> </body></html>";
String jala_kayu = "<html><body><iframe width='100%' height='100%' frameborder='0' style='border:0' src='https://www.google.com/maps/embed/v1/directions?key=AIzaSyD7mjSU3lSzYHgGcUglDog9cxLNjZDq_68&origin=12.9313121,77.5154951&destination=269 Jalan Kayu, Singapore&mode=driving'></iframe> </body></html>";
webView.setWebViewClient(new myWebClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setSupportZoom(true);
webView.loadDataWithBaseURL(null, jala_kayu, "text/html", "UTF-8", null);
}
public class myWebClient extends WebViewClient
{
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
pd.setMessage("");
pd.setIndeterminate(true);
pd.setCanceledOnTouchOutside(false); // updated jul 3
pd.setCancelable(true); // updated jul 3
if (!isFinishing()) // updated jul 3
pd.show();
super.onPageStarted(view, url, favicon);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.w("mCurrentUrl",""+url);
view.loadUrl(url);
return true;
}
// Here the page loading will stop so dismiss the ProgressDialog
public void onPageFinished(WebView view, String url) {
// this is what we should do
webView.invalidate();
pd.dismiss();
}
}
@Override
public void onBackPressed() {
System.gc();
super.onBackPressed();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
webView.goBack();
webView.invalidate();
return true;
}
return super.onKeyDown(keyCode, event);
}
代码完全适用于第一次点击,webview中的谷歌地图打开,但之后返回并更改了viewpager,如果我点击按钮再次。 webview显示空白的白色屏幕。我检查了所有捆绑的数据,甚至在浏览器中检查了地图网址。有用 。但在webview内部它无法正常工作。我认为有一些与webview相关的东西在第一次没有刷新。请帮忙 。 。提前谢谢你
答案 0 :(得分:0)
将此内容添加到您的代码中:webView.getSettings()。setDomStorageEnabled(true);