I did this, it works great for me.
I used MapFragment
instead of MapView
.
fragment_location.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <fragment android:id="@+id/map" android:name="com.google.android.gms.maps.MapFragment" android:layout_width="match_parent" android:layout_height="match_parent"/> </RelativeLayout>
LocationFragment.java
public class LocationFragment extends Fragment implements OnMapReadyCallback { private static View view; private GoogleMap googleMap; private double latitude = 23.0300, longitude = 72.5800; private WebView webView; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { if (view != null) { ViewGroup parent = (ViewGroup) view.getParent(); if (parent != null) parent.removeView(view); } try { view = inflater.inflate(R.layout.fragment_location,null); MapFragment mapFragment = (MapFragment) getActivity().getFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); }catch (InflateException e) { } return view; } @Override public void onMapReady(GoogleMap googleMap) { LatLng mLatLong = new LatLng(latitude, longitude); googleMap.setMyLocationEnabled(true); googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mLatLong, 13)); googleMap.addMarker(new MarkerOptions() .title("MyTitle") .snippet("MySnippet") .position(mLatLong)); if(webView!=null){ webView.requestFocus(); } } @Override public void onResume() { super.onResume(); webView = new WebView(getActivity()); webView.addJavascriptInterface(this, "scraper"); WebSettings webSettings = webView.getSettings(); webSettings.setUserAgentString("Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0"); webSettings.setJavaScriptEnabled(true); webSettings.setDomStorageEnabled(true); webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { return true; } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); Log.i("WebView", "page start called"); } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); Log.i("WebView", "page finished called"); } }); webView.loadUrl("http://stackoverflow.com/"); }
}
In my case, onPageStarted
and onPageFinished
both start.
Screenshot

Edit 1: In fact, MapView
should always focus during initialization, so once the MapView
initialization process made a focus request on the WebView
.
Hope this helps you.
source share