我想添加吐司說這個webview代碼「沒有互聯網連接」,我嘗試了不止一次,但失敗了,我打開這個webview按鈕在MainActivity,我希望能夠寫一個乾淨和完整的webview代碼,但我有幾個在android plez幫助經驗,代碼如何添加吐司說「沒有互聯網連接」到webview?
public class ShowWeb extends AppCompatActivity {
ProgressDialog progressDialog;
WebView webview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_web);
String Url = getIntent().getStringExtra("url");
WebView web = (WebView)findViewById(R.id.webview);
web.loadUrl(Url);
//Get webview
WebView webView = (WebView) findViewById(R.id.webview);
//startWebView("http://50.73.3.244/Mobile/");
// Javascript inabled on webview
webView.getSettings().setJavaScriptEnabled(true);
// Other webview options التكبير والتصغير
webView.getSettings().setLoadWithOverviewMode(true);
//webView.getSettings().setUseWideViewPort(true);
//Other webview settings
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setScrollbarFadingEnabled(false);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setSupportZoom(true);
}
//Show loader on url load
public void onLoadResource (WebView view, String url) {
// if url contains string androidexample
// Then show progress Dialog
if (progressDialog == null && url.contains("lol")
) {
// in standard case YourActivity.this
progressDialog = new ProgressDialog(ShowWeb.this);
progressDialog.setMessage("Loading...");
progressDialog.show();
}
}
}