Android WebView click open within WebView not a default browser

后端 未结 12 2026
迷失自我
迷失自我 2020-11-27 16:34

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 automatica

12条回答
  •  清歌不尽
    2020-11-27 17:02

    Here is my code how to resolve the above problem (when cliking on link it asking for default browser to opn the link)

    import android.os.Bundle;import android.annotation.SuppressLint;import android.app.Activity;
    import android.view.Menu;import android.webkit.WebChromeClient;
    import android.webkit.WebView;public class MainActivity extends Activity{
    `@SuppressLint("SetJavaScriptEnabled")@Override protected void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);String url="http://google.com";WebView Webview=(WebView) this.findViewById(R.id.webView1);     Webview.getSettings().setJavaScriptEnabled(true);Webview.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;}`}
    

提交回复
热议问题