Issue
I did one sample application using WebView, in that web view the URL comes from web services. It's working fine, but if I click any link within that WebView, its automatically go for default web browser. But I want to open within my application web view only. Here my code:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String url ="http://www.cementegypt.com/m/";
WebView view =(WebView) this.findViewById(R.id.webView1);
view.getSettings().setJavaScriptEnabled(true);
view.loadUrl(url);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Solution
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.
Answered By - Shobhit Puri
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.