在帶有 android studio 的 java 中,我通過添加以下代碼來實現這一點:webView.getSettings().setJavaScriptEnabled(true);webView.getSettings().setLoadWithOverviewMode(true);webView.getSettings().setUseWideViewPort(true);webView.getSettings().setSupportZoom(true);webView.getSettings().setBuiltInZoomControls(true);webView.getSettings().setDisplayZoomControls(false);webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);webView.setScrollbarFadingEnabled(false);但我不知道如何在 React-Native 中做到這一點,我嘗試了一些 css 風格,但沒有成功。這是我在 React 中的 webview:<WebView ref="WebView" scalesPageToFit={true} onLoadStart={this.onLoadStart} onLoadEnd={this.onLoadEnd} source = {{ uri:this.props.navigation.getParam('main_url', 'https://xxxx.xxx/')}} style={{backgroundColor: 'transparent',width: '100%'}}/>:null}
2 回答

茅侃侃
TA貢獻1842條經驗 獲得超22個贊
使用用戶代理。
注意:這曾經僅適用于 Android。對于 iOS,您可以使用此鏈接Change User-Agent 現在它似乎適用于 iOS 和 android
<Webview
userAgent="Mozilla/5.0 (Linux; Android 8.0.0; Pixel 2 XL Build/OPD1.170816.004) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3714.0 Mobile Safari/537.36"
/>

慕的地6264312
TA貢獻1817條經驗 獲得超6個贊
受 Sanyam 評論的啟發,您需要設置用戶代理以將其加載為移動設備:
<WebView
userAgent={DeviceInfo.getUserAgent() + " - MYAPPNAME - android "}
{...otherProps}
/>
添加回答
舉報
0/150
提交
取消