java - User stay in app when user click in to site in webview -
i have webview in android app, when navigates around site, opens in new window, want stay inside webview.. there way easily? here code in activity:
public class webview1 extends activity { webview web1; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_web_view); intent in=getintent(); string urll= in.getstringextra("url"); web1=(webview)findviewbyid(r.id.web); web1.loadurl(urll); }
attach webviewclient
webview
, shouldoverrideurlloading()
on webviewclient
loads url webview
, returns true.
for example, activity implements approach:
/*** copyright (c) 2008-2015 commonsware, llc licensed under apache license, version 2.0 (the "license"); may not use file except in compliance license. may obtain copy of license @ http://www.apache.org/licenses/license-2.0. unless required applicable law or agreed in writing, software distributed under license distributed on "as is" basis, without warranties or conditions of kind, either express or implied. see license specific language governing permissions , limitations under license. _the busy coder's guide android development_ https://commonsware.com/android */ package com.commonsware.android.browser4; import android.app.activity; import android.os.bundle; import android.webkit.webview; import android.webkit.webviewclient; public class browserdemo4 extends activity { webview browser; @override public void oncreate(bundle icicle) { super.oncreate(icicle); setcontentview(r.layout.main); browser=(webview)findviewbyid(r.id.webkit); browser.setwebviewclient(new webviewclient() { @override public boolean shouldoverrideurlloading(webview view, string url) { view.loadurl(url); return(true); } }); browser.loadurl("https://commonsware.com"); } }
(from this sample project)
Comments
Post a Comment