我有一个 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/