fix: 禁用WebView文本缩放并修复Portal定位

安卓端MainActivity中强制WebView文本缩放为100%,防止系统字体大小影响布局。capacitor.config.ts同步禁用WebView文本缩放及键盘视口调整。CSS中统一禁用文本大小调整,修复Edge-to-Edge模式下Portal容器定位问题,提升移动端显示一致性。
This commit is contained in:
谦君
2025-12-25 20:40:02 +08:00
parent ca1aed1e9b
commit 27d60ae71a
3 changed files with 44 additions and 0 deletions

View File

@@ -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%,忽略系统字体缩放设置
}
}
}

View File

@@ -11,6 +11,15 @@ const config: CapacitorConfig = {
buildOptions: {
keystorePath: undefined,
keystoreAlias: undefined
},
// 禁用 WebView 文本缩放,防止系统字体设置影响布局
webContentsDebuggingEnabled: false,
allowMixedContent: false
},
plugins: {
// 禁用键盘自动调整视口
Keyboard: {
resize: 'none'
}
}
}

View File

@@ -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;
}