WebView 正在裁剪 android 4.4 中的网页 [英] WebView is clipping the webpage in android 4.4

查看:37
本文介绍了WebView 正在裁剪 android 4.4 中的网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WebView 正在剪辑 Android 4.4 上的网页.这是它的外观:

WebView is clipping the webpage on Android 4.4. Here is how it looks:

它在谷歌浏览器中正确打开.我希望它在 webview 中像这样打开.

It is opening correctly in google chrome. I want it to open like this in the webview.

以下是我的代码:

activity_main.xml

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">


    <WebView
        android:id="@+id/web_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java

MainActivity.java

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {
    WebView webView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        webView=findViewById(R.id.web_view);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setWebViewClient(new WebViewClient());
        webView.getSettings().setDomStorageEnabled(true);
        webView.getSettings().setAllowContentAccess(true);
        webView.getSettings().setAllowFileAccess(true);
        webView.getSettings().setDatabaseEnabled(true);
        webView.getSettings().setDomStorageEnabled(true);
        webView .getSettings().setLoadWithOverviewMode(true);
        webView .getSettings().setUseWideViewPort(true);
        webView.loadUrl("https://viftbox.com/");
    }
}

推荐答案

对于在 Android 上使用最新的 WebView 引擎并且您不能使用 Android System WebView 或 Google Chrome:

For using a recent WebView engine on Android and you can't use Android System WebView or Google Chrome:

在 Android 5.0 之前,对 Android WebView 的改进仅限于操作系统升级/更新.因此,建议使用 NOW DEPRECATED Crosswalk Project 作为 WebView.虽然该站点不再存在,但 它的幽灵存在于存档中.org 我不知道是否有足够的站点存在于那里以供使用.如果您无法更改硬件并且需要更新的 webkit 功能,这可能是一个解决方案.

Prior to Android 5.0 improvements to the Android WebView was limited to OS upgrades/updates. So the recommendation was to use the NOW DEPRECATED Crosswalk Project as the WebView. While the site no longer exists, its ghost exists on archive.org I don't know if enough of the site survives there to be useful. This might be a solution if you are unable to change hardware and need more recent webkit features.

由于 Crosswalk 项目不再更新,或者它没有您需要的功能,我了解到 Mozilla 有一个 GeckoView 包装了他们的 Gecko 渲染引擎.

As the Crosswalk Project is no longer updated, or it doesn't have the features you need, I've learned that Mozilla has a GeckoView which wraps their Gecko render engine.

请注意,根据 Mozilla 的文档,他们拥有自己的 API,因此 GeckoView 不能直接替代 Android 的 WebView,因此必须为集成做出一些努力.

Note that according to Mozilla's documentation they have their own APIs so GeckoView is NOT a drop-in replacement for Android's WebView, so some effort must be made for integration.

无论哪种方式包含自定义 webview 引擎都会增加 APK 大小.

Either way including a custom webview engine will add to the APK size.

这篇关于WebView 正在裁剪 android 4.4 中的网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆