public class MainActivity extends Activity {
public WebView mywebview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
mywebview = (WebView) findViewById(R.id.webview);
WebSettings webSettings = mywebview.getSettings();
webSettings.setJavaScriptEnabled(true);
mywebview.loadUrl("http://infbooster.com/");
mywebview.setWebViewClient(new WebViewClient());
}
@Override
public void onBackPressed() {
if (mywebview.canGoBack()) {
mywebview.goBack();
} else
super.onBackPressed();
}
我刚刚开始学习编码 . 以上是我正在使用的代码 . 我设法将我自己的网站变成了应用程序,但是有一个问题,我无法解决它 . 在我的网站上,有一个指向WhatsApp消息的链接 . 我在下面找到了这些代码,但我不知道如何在下面放置此代码 .
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("http://infbooster.com")) {
// This is my website, so do not override; let my WebView load the page
return false;
}
// Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
}
这是我在网上得到的示例代码,我不知道如何实现它 . 希望有人能指导我完成这件事 .