首页 > 解决方案 > WebView 不显示 KOLIBRI 登录页面

问题描述

嗨,我是 Android Studio 的新手。我正在开发一个使用 WebView 打开 http url 的应用程序。这个 http url 用于访问我正在工作的学校的学习资料。webview 在其他网站上正常工作,也可以访问我的路由器设置。我无法让它在http://192.168.100.73:8080中工作。webview 仅显示图标,但当我删除行 myWebView.setWebViewClient((new WebViewClient())); 我不想这样做。我无法在谷歌中搜索类似的问题。

我的清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="org.gves.studentresources">

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.StudentResources"
        android:usesCleartextTraffic="true">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:label="@string/app_name"
            android:theme="@style/Theme.StudentResources.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

片段布局

<WebView
    android:id="@+id/webview1"
    android:layout_width="409dp"
    android:layout_height="729dp"
    android:layout_marginStart="1dp"
    android:layout_marginTop="1dp"
    android:layout_marginEnd="1dp"
    android:layout_marginBottom="1dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

片段java类

    binding = FragmentHomeBinding.inflate(inflater, container, false);
    View root = binding.getRoot();


    WebView myWebView = root.findViewById(R.id.webview1);
    myWebView.getSettings().setJavaScriptEnabled(true);
    //myWebView.setWebViewClient((new WebViewClient()));
    myWebView.loadUrl("http://192.168.100.73:8080");

    return root;
}

应用程序运行时的屏幕截图。webview 显示图标,但没有任何反应。 使用新的 webview 代码

删除 myWebView.setWebViewClient((new WebViewClient())); 时的屏幕截图 没有新的 webview 代码的行 代码

我正在使用 Android Studio 的默认导航抽屉模板。我希望你能帮我解决这个问题。

标签: androidandroid-studiohttpwebview

解决方案


我通过添加这一行来解决我的问题。

myWebView.getSettings().setDomStorageEnabled(true);

但我还有另一个问题。Webview 中的下载资源按钮丢失。bluestaks 中的 google chrome 与 android studio 模拟器相比


推荐阅读