gpt4 book ai didi

javascript - Android webview 无法正常显示

转载 作者:行者123 更新时间:2023-12-03 02:00:39 25 4
gpt4 key购买 nike

我有一个 Android WebView,它只显示网站的正确蓝色背景,但没有显示任何内容。我在 iOS Web View 中正确打开了相同的网站。

public class MainActivity extends AppCompatActivity {

private WebView mWebView;

@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mWebView = findViewById(R.id.webView);

WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if( url.startsWith("http:") || url.startsWith("https:") ) {
if (url.contains("test.com")) {
return false;
}
}

// Otherwise allow the OS to handle things like tel, mailto, etc.
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity( intent );
return true;
}
});

mWebView.loadUrl("https://test.com");

最佳答案

添加:

webSettings.setDomStorageEnabled(true);

解决了问题。

关于javascript - Android webview 无法正常显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50052210/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com