0

Simple I want to show a web page in my activity with default action bar on top. How I can do it? App works properly without crash. Web site is opening but not embeded. It is opening in my Chrome Browser.

also I tried this solution but also it opens web page in chrome web browser http://developer.android.com/guide/webapps/webview.html#UsingJavaScript

... ... ...

public class xx extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    WebView webview = new WebView(this);
    setContentView(webview);
    webview.loadUrl("http://google.com/");

}

}

...

Clifford
  • 88,407
  • 13
  • 85
  • 165
hakki
  • 6,181
  • 6
  • 62
  • 106
  • possible duplicate of [Clicking URLs opens default browser](http://stackoverflow.com/questions/2378800/clicking-urls-opens-default-browser), as the same behavior is also triggered by a redirect, and Google is probably issuing a redirect to your local version of Google. – CommonsWare May 02 '14 at 21:19

2 Answers2

0

You need to set a WebViewClient that will handle the urls within the same WebView. If no WebViewClient is present, by default the WebView will pass the urls to the ActivityManager, meaning the loadUrl() method would open a browser each time a url is passed from the webView.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    WebView webView = new WebView(this);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebViewClient(new WebViewClient());
    webView.loadUrl("http://www.google.com");
    setContentView(webView);
}

and don't forget to declare in your AndroidManifest:

<uses-permission android:name="android.permission.INTERNET" />
ILovemyPoncho
  • 2,762
  • 2
  • 24
  • 37
0

Use like this.

    WebView webView = new WebView(this);
    webView.getSettings().setJavaScriptEnabled(true); 
    webView.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }

    });
    webView.loadUrl("http://www.google.com");
Shadow
  • 6,864
  • 6
  • 44
  • 93