java - 为什么我的网页没有显示在我的 WebView 中?
问题描述
我不会说英语,对不起,有人可以帮帮我吗?我想用 web 视图显示我的公司网页,我将我公司网站的 url 输入到我的 Activity 并使用 loadUrl() 加载,但是当我运行我的项目时它从不显示网页。为什么会发生?我在浏览器中输入了一个 url,它可以工作,但在 web 视图中它不起作用。请帮我
这是我的 MainActivity.java
package com.ithits.hits;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
private WebView webView;
private String webUrl = "https://hits.hokimtong.org/";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.webView);
webView.setWebViewClient(new MyWebViewClient());
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl(webUrl);
Log.e("tag", "Url Loading " + webUrl");
}
private class MyWebViewClient extends WebViewClient{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}
这是我的 AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ithits.hits">
<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/AppTheme">
<activity android:name=".MainActivity"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
这是我的 activity_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity"/>
解决方案
我的问题已经解决了谢谢大家的帮助,我的设备操作系统版本的问题,它太旧了,我必须购买另一个设备来运行我的项目
推荐阅读
- c++ - 如何按字母顺序显示我的数组映射?
- swift - 从目标视图返回时,SwiftUI NavigationLink 显示为突出显示
- amazon-web-services - AWS ssh 公钥被拒绝
- css - 如何将按钮移动到中心
- vue.js - 在 nuxt 的 head 标签中包含自定义脚本
- flutter - Flutter 中的嵌套期货返回列表
- mysql - Mysqldump 将外来字符替换为 utf8mb4 数据库
- api - 在 .net 核心 NLayer 架构中处理请求时发生未处理的异常
- react-rainbow-components - 如何在库 react-rainbow-component 中手动自定义头像的大小?
- python - 使用 Python3 和 jinja2 从嵌套的 Json 响应中获取信息