当我单击 WebView 中的链接时,Android 打开浏览器而不是更改 WebView 中的 URL。
这是我在 WebView 所在的片段(R.layout.webview 仅包含 WebView):
package com.example.fragments;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
public class EuDetailsFragment extends Fragment {
private WebView viewer;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
viewer = (WebView) inflater.inflate(R.layout.webview, container, false);
return viewer;
}
public void updateUrl(String newUrl) {
Log.d("EuDetailsFragment", "Updating url...");
WebView detailsView = (WebView) getView().findViewById(R.id.detailsView);
detailsView.loadUrl(newUrl);
}
}