Reputation: 5311
I am working on an Android project in which I am loading an HTML page from Internet, not locally and then displaying it in WebView. It works fine, but unfortunately, when I click on any of the element in WebView, it opens the link in Browser.
What changes do I need to make so that any links clicked within the web-view will be opened by Web-view itself. Thank you.
Code :
public class ContainerActivity extends Activity {
private WebView mWebView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contain);
mWebView = (WebView)findViewById(R.id.wvPortal);
mWebView.loadUrl("www.domain.com/path/to/index.html");
WebSettings mWebSettings = mWebView.getSettings();
mWebSettings.setJavaScriptEnabled(true);
} }
contain.xml :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<WebView
android:id="@+id/wvPortal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="@android:color/transparent"
/>
</RelativeLayout>
Kindly let me know. Thank you.
Upvotes: 0
Views: 57
Reputation: 1963
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
Upvotes: 1