From 27d60ae71a8e8187c8a30d839d1f43e08559bc0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A6=E5=90=9B?= <73606411+setube@users.noreply.github.com> Date: Thu, 25 Dec 2025 20:40:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A6=81=E7=94=A8WebView=E6=96=87?= =?UTF-8?q?=E6=9C=AC=E7=BC=A9=E6=94=BE=E5=B9=B6=E4=BF=AE=E5=A4=8DPortal?= =?UTF-8?q?=E5=AE=9A=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 安卓端MainActivity中强制WebView文本缩放为100%,防止系统字体大小影响布局。capacitor.config.ts同步禁用WebView文本缩放及键盘视口调整。CSS中统一禁用文本大小调整,修复Edge-to-Edge模式下Portal容器定位问题,提升移动端显示一致性。 --- .../java/games/wenzi/ogame/MainActivity.java | 13 +++++++++++ capacitor.config.ts | 9 ++++++++ src/style.css | 22 +++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/android/app/src/main/java/games/wenzi/ogame/MainActivity.java b/android/app/src/main/java/games/wenzi/ogame/MainActivity.java index 9489197..a2586bd 100644 --- a/android/app/src/main/java/games/wenzi/ogame/MainActivity.java +++ b/android/app/src/main/java/games/wenzi/ogame/MainActivity.java @@ -3,6 +3,8 @@ package games.wenzi.ogame; import android.graphics.Color; import android.os.Bundle; import android.view.Window; +import android.webkit.WebSettings; +import android.webkit.WebView; import androidx.core.view.WindowCompat; import androidx.core.view.WindowInsetsControllerCompat; import com.getcapacitor.BridgeActivity; @@ -28,4 +30,15 @@ public class MainActivity extends BridgeActivity { controller.setAppearanceLightNavigationBars(false); } } + + @Override + public void onStart() { + super.onStart(); + // 禁用 WebView 文本缩放,防止系统字体大小设置影响布局 + WebView webView = getBridge().getWebView(); + if (webView != null) { + WebSettings settings = webView.getSettings(); + settings.setTextZoom(100); // 固定为 100%,忽略系统字体缩放设置 + } + } } diff --git a/capacitor.config.ts b/capacitor.config.ts index 2ede4b6..347bd7e 100644 --- a/capacitor.config.ts +++ b/capacitor.config.ts @@ -11,6 +11,15 @@ const config: CapacitorConfig = { buildOptions: { keystorePath: undefined, keystoreAlias: undefined + }, + // 禁用 WebView 文本缩放,防止系统字体设置影响布局 + webContentsDebuggingEnabled: false, + allowMixedContent: false + }, + plugins: { + // 禁用键盘自动调整视口 + Keyboard: { + resize: 'none' } } } diff --git a/src/style.css b/src/style.css index 5bed97c..87d1739 100644 --- a/src/style.css +++ b/src/style.css @@ -123,6 +123,10 @@ html { /* 平滑过渡 */ transition: background-color 0.3s ease, color 0.3s ease; + /* 禁用文本大小调整,防止移动端自动放大文本 */ + -webkit-text-size-adjust: 100%; + -moz-text-size-adjust: 100%; + text-size-adjust: 100%; } body { @@ -217,4 +221,22 @@ aside nav a:hover button { :root:not(.dark) .tooltip-content-custom { background-color: oklch(0.3 0.02 85) !important; color: oklch(0.95 0.008 85) !important; +} + +/* 修复 Edge-to-Edge 模式下 Portal 容器的定位问题 */ +[data-reka-portal], +[data-radix-portal] { + position: fixed !important; + left: 0 !important; + top: 0 !important; + right: 0 !important; + bottom: 0 !important; + pointer-events: none; + padding: 0 !important; + margin: 0 !important; +} + +[data-reka-portal] > *, +[data-radix-portal] > * { + pointer-events: auto; } \ No newline at end of file