【问题标题】:Error occured in my simple Android Web view Application我的简单 Android Web 视图应用程序发生错误
【发布时间】:2021-06-19 06:58:26
【问题描述】:

导入 android.os.Bundle 导入 kotlinx.android.synthetic.main.activity_main.*

类 MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    webviewsetup()
}

private fun webviewsetup() {
    wb_webview.webviewclient = webviewclient()


    wb_webview.apply {
        loadurl(url"https://fullmart.in/")
        settings.javaScriptenabled = true
        settings.safebrowsingenabled = true
    }
}

}

我在 webviews 和加载 url 中遇到错误,甚至在设置上也有人可以帮助我解决

【问题讨论】:

  • 请在此处发布您的错误。

标签: android android-studio kotlin webview android-app-bundle


【解决方案1】:

试试下面的代码,它工作正常。

//Add internet permission in manifest file
<uses-permission android:name="android.permission.INTERNET"/>


//activity.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<WebView
    android:id="@+id/wb_webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</LinearLayout>


//activity code
class TestActivity : AppCompatActivity() {
private lateinit var webView: WebView
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_test)
    webView = findViewById(R.id.wb_webview)
    webView.settings.apply {
        javaScriptEnabled = true
        safeBrowsingEnabled = true
    }
    webView.apply {
        loadUrl("https://fullmart.in/")
    }
  }
 }

【讨论】:

    猜你喜欢
    • 2016-10-21
    • 2016-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多