android - WebView 正在剪辑 android 4.4 中的网页
问题描述
WebView 正在剪辑 Android 4.4 上的网页。这是它的外观:
它在谷歌浏览器中正确打开。我希望它在 webview 中像这样打开。
以下是我的代码:
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 System WebView 或 Google Chrome:
在 Android 5.0 之前,对 Android WebView 的改进仅限于操作系统升级/更新。所以建议使用NOW DEPRECATED Crosswalk Project作为 WebView。虽然该站点不再存在,但它的幽灵存在于 archive.org我不知道该站点是否有足够的站点存在以发挥作用。如果您无法更改硬件并且需要更新的 webkit 功能,这可能是一个解决方案。
由于 Crosswalk 项目不再更新,或者它没有您需要的功能,我了解到 Mozilla 有一个GeckoView包装了他们的 Gecko 渲染引擎。
请注意,根据 Mozilla 的文档,他们有自己的 API,因此 GeckoView不是Android 的 WebView 的替代品,因此必须为集成做出一些努力。
无论哪种方式,包括自定义 webview 引擎都会增加 APK 大小。
推荐阅读
- amazon-web-services - 我们可以使用 AWS Data Migration Service 从 Aurora Serverless 作为源进行复制吗?
- c# - 替换完全匹配的字符串
- c++ - 如何在 C++ 中将迭代器作为函数参数传递
- token - 如何仅使用 OAuth 访问令牌将 ibm watson 聊天机器人与 slack 集成
- c++ - MinGW 的“-fno-elide-constructors”的类似物是什么?
- mediawiki - 具有多个表达式的 mediawiki api 搜索查询
- java - 在枚举中实现 Runnable
- django - 如何在Django rest框架中嵌套抽象关系?
- regex - 如何在 PowerShell 中使用带有正则表达式的条件语句?
- embedded-linux - 嵌入式 Linux 的启动卡住了。如何调试?