使用Kotlin 敲了一个WebView 练手案例;
正常加载一个Url,及加载失败后,点击重加载按钮后,重新加载;
上代码:
class MainActivity : AppCompatActivity(), View.OnClickListener { private val url = "https://www.baidu.com/" var isError: Boolean = false override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) re_fresh.setOnClickListener(this) // Get the web view settings instance val settings = mywebview.settings // Enable java script in web view settings.javaScriptEnabled = true // Enable and setup web view cache settings.setAppCacheEnabled(true) settings.cacheMode = WebSettings.LOAD_DEFAULT settings.setAppCachePath(cacheDir.path) settings.setSupportZoom(false) // Enable zooming in web view settings.builtInZoomControls = false setting