千萬(wàn)里不及你
2022-07-06 09:43:28
在帶有 android studio 的 java 中,我通過(guò)添加以下代碼來(lái)實(shí)現(xiàn)這一點(diǎn):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 中做到這一點(diǎn),我嘗試了一些 css 風(fēng)格,但沒(méi)有成功。這是我在 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貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超21個(gè)贊
使用用戶代理。
注意:這曾經(jīng)僅適用于 Android。對(duì)于 iOS,您可以使用此鏈接Change User-Agent 現(xiàn)在它似乎適用于 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貢獻(xiàn)1817條經(jīng)驗(yàn) 獲得超6個(gè)贊
受 Sanyam 評(píng)論的啟發(fā),您需要設(shè)置用戶代理以將其加載為移動(dòng)設(shè)備:
<WebView
userAgent={DeviceInfo.getUserAgent() + " - MYAPPNAME - android "}
{...otherProps}
/>
添加回答
舉報(bào)
0/150
提交
取消