Android examples for android.webkit:WebView
show URL in WebView
import android.content.Context; import android.util.Log; import android.view.ViewGroup; import android.webkit.ConsoleMessage; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; public class Main{ protected static final String TAG = "WebviewUtil"; public static WebView showWebView(Context context, ViewGroup container) { WebView view = new WebView(context); view.setWebChromeClient(new WebChromeClient() { @Override//from w w w . ja va2 s. co m public boolean onConsoleMessage(ConsoleMessage consoleMessage) { Log.i(TAG, "msg:" + consoleMessage.message()); return super.onConsoleMessage(consoleMessage); } }); view.getSettings().setJavaScriptEnabled(true); view.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { Log.v(TAG, "url:" + url); return super.shouldOverrideUrlLoading(view, url); } @Override public void onLoadResource(WebView view, String url) { super.onLoadResource(view, url); Log.d(TAG, "loadResource: url:" + url); } }); container.removeAllViews(); container.addView(view); view.loadUrl("http://java2s.com"); return view; } }