3

In my xml file I'm having text and below that text,I have placed a webview. I am trying to open google's home page in Webview. Instead of opening in webview,webpage is opening on browser.What I want is web page should load in webview which is below some text.Below is my code:

 <TextView android:id="@+id/txt" android:text="Hello Android" android:textSize="30sp" android:textStyle="bold" android:textColor="#003399" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_centerHorizontal="true" /> <WebView android:id="@+id/webview" android:layout_marginTop="50dp" android:layout_below="@id/txt" android:layout_height="fill_parent" android:layout_width="fill_parent"/> 

Kindly help to solve this.Thank you

1

2 Answers 2

2

This is because a combination of two things:

  1. the WebViewClient is not set (set to null), this makes the WebView try and offer every navigation as an intent to the system. Since you have a browser installed the system will try to handle that navigation there.
  2. going to google.com ususally results in a redirect, which is why the stuff about navigations in the previous point matters.

Try this:

webview = (WebView) findViewById(R.id.webview); webview.setWebViewClient(new WebViewClient()); 
Sign up to request clarification or add additional context in comments.

Comments

0

Create your activity and than use this code...

mWebview = (WebView) findViewById(R.id.webview); mWebview.getSettings().setJavaScriptEnabled(true); // enable javascript

 mWebview.setWebViewClient(new WebViewClient() { public void onReceivedError(WebView view, int errorCode,String description, String failingUrl) { Toast.makeText(youractivity_name.this, description, Toast.LENGTH_SHORT).show(); } }); mWebview.loadUrl("http://www.yahoo.com"); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.