Opening Webview Not in New Browser

Opening webview not in new browser

The layout should something similar to this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:id="@+id/button1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_weight="1"/>
<Button android:id="@+id/button2"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_weight="1" />
</LinearLayout>
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>

And you can also refer to the Need help changing from stock android browser to webview to see if you are launching the url correctly.

Android WebView click open within WebView not a default browser

You have to set up a webViewClient for your webView.

Sample:

this.mWebView.setWebViewClient(new WebViewClient(){

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
view.loadUrl(url);
return true;
}
});

how to open other links in browser not in webview?

you can handle every url as you wish just set up your webview via customized WebViewClient

mWebView.webViewClient = MyWebViewClient()

}

private inner class MyWebViewClient : WebViewClient() {

override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
if (!url.contains("little.com")) {//for example
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
startActivity(intent)
return true
}

mWebView.loadUrl(url)
return false

WebView not working, launching the url externally in browser. Displaying webpage inside app

As per this answer: How to load external webpage inside WebView you need to set a WebViewClient before you call loadUrl:

webView.setWebViewClient(new WebViewClient());

The reason you're being sent to the browser is that if no WebViewClient is set then the default action for navigations is to forward them to the browser.

Android WebView links to same window with target=_blank to open new window

First,

mWebView.getSettings().setSupportMultipleWindows(true);

Then in WebChromeClient, override OnCreateWindow()

    private class MyWebChromeclient extends WebChromeClient {

@Override
public boolean onCreateWindow(WebView view, boolean isDialog,
boolean isUserGesture, Message resultMsg) {

WebView newWebView = new WebView(WebViewActivity2.this);
view.addView(newWebView);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(newWebView);
resultMsg.sendToTarget();

newWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW);
browserIntent.setData(Uri.parse(url));
startActivity(browserIntent);
return true;
}
});
return true;
}

Android WebView click open with in WebView not a default browser?

Try:

WebView view =(WebView)findViewById(R.id.webView1);
view.getSettings().setJavaScriptEnabled(true);
view.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});

Source: This answer by @momo on very similar question: Link should be open in same web view in Android . Hope this helps.



Related Topics



Leave a reply



Submit