WebView正在裁剪android 4.4中的网页

问题描述 投票:1回答:1

WebView正在裁剪Android 4.4上的网页。外观如下:In WebView

它在谷歌浏览器中正确打开。我希望它在webview中这样打开。In Chrome

以下是我的代码:

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

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-webview
1个回答
0
投票

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

在Android 5.0之前,对Android WebView的改进仅限于操作系统升级/更新。因此,建议使用NOW DEPRECATED Crosswalk Project作为WebView。虽然该站点不再存在,但是its ghost exists on archive.org我不知道是否有足够的站点可以生存下来而有用。如果您无法更改硬件并且需要更多最新的Webkit功能,这可能是一个解决方案。

由于Crosswalk Project不再更新,或者它不具有您需要的功能,因此我了解到Mozilla的GeckoView封装了他们的Gecko渲染引擎。

请注意,根据Mozilla的文档,它们具有自己的API,因此NOT是Android WebView的直接替代品,因此必须付出一些努力进行集成。

无论哪种方式,都会增加APK的大小。

© www.soinside.com 2019 - 2024. All rights reserved.