|
|
@@ -1,57 +0,0 @@
|
|
|
-package com.grkj.iscs.activity
|
|
|
-
|
|
|
-import android.annotation.SuppressLint
|
|
|
-import android.os.Bundle
|
|
|
-import android.view.KeyEvent
|
|
|
-import android.view.View
|
|
|
-import android.webkit.WebViewClient
|
|
|
-import androidx.appcompat.app.AppCompatActivity
|
|
|
-import com.grkj.iscs.databinding.ActivityWebBinding
|
|
|
-
|
|
|
-
|
|
|
-class WebActivity : AppCompatActivity() {
|
|
|
-
|
|
|
- private var mBinding: ActivityWebBinding? = null
|
|
|
- override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
- super.onCreate(savedInstanceState)
|
|
|
- mBinding = ActivityWebBinding.inflate(layoutInflater)
|
|
|
- setContentView(mBinding!!.root)
|
|
|
-
|
|
|
- createWebView()
|
|
|
- }
|
|
|
-
|
|
|
- @SuppressLint("SetJavaScriptEnabled")
|
|
|
- private fun createWebView() {
|
|
|
- // 创建 WebView 实例并通过 id 绑定我们刚在布局中创建的 WebView 标签
|
|
|
- // 这里的 R.id.webview 就是 activity_main.xml 中的 WebView 标签的 id
|
|
|
-
|
|
|
-
|
|
|
- // 设置 WebView 允许执行 JavaScript 脚本
|
|
|
- mBinding!!.webView.settings.javaScriptEnabled = true
|
|
|
-
|
|
|
- // 确保跳转到另一个网页时仍然在当前 WebView 中显示
|
|
|
- // 而不是调用浏览器打开
|
|
|
- mBinding!!.webView.webViewClient = WebViewClient()
|
|
|
-
|
|
|
- // 加载指定网页
|
|
|
-// val url = "https://yaie.hihakid.com/homePage"
|
|
|
- val url = "www.ithome.com"
|
|
|
- mBinding!!.webView.loadUrl(url)
|
|
|
-
|
|
|
- mBinding!!.webView.setOnKeyListener(View.OnKeyListener { v, keyCode, event ->
|
|
|
- if (keyCode == KeyEvent.KEYCODE_BACK && mBinding!!.webView.canGoBack()) {
|
|
|
- mBinding!!.webView.goBack()
|
|
|
- return@OnKeyListener true
|
|
|
- }
|
|
|
- false
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- override fun onBackPressed() {
|
|
|
- if (mBinding!!.webView.canGoBack()) {
|
|
|
- mBinding!!.webView.goBack()
|
|
|
- } else {
|
|
|
- super.onBackPressed()
|
|
|
- }
|
|
|
- }
|
|
|
-}
|