Answer the question
In order to leave comments, you need to log in
How to open link from WebView in new activity with WebView?
Two days of searching gave such a result, I feel that I'm close. Help fix the code
public class MainActivity extends AppCompatActivity {
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = findViewById(R.id.webhome);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.loadUrl("https://www.google.com");
webView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest URL) {
Intent intent;
switch (view.getUrl()) {
case R.id.webhome:
intent = new Intent("info.android.intent.action.URL");
intent.putExtra("url", URL.getUrl().toString());
startActivity(intent);
return super.shouldOverrideUrlLoading(view, URL);
}
return false;
}
});
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question