[英]WebView in Android Studio does not show sites properly (i.e. www.google.com is without logo, search bar and all the stuff on upper screen)
I have a problem with showing simple google.com in my WebView. Tried this on few emulators and 2 phones, all the same, something is wrong with my code.我在我的 WebView 中显示简单的 google.com 时遇到问题。在几个模拟器和 2 部手机上试过这个,都一样,我的代码有问题。
1. Issue 1.问题
2. Code 2.代码
I added permission in Manifest.我在清单中添加了权限。
Trying to solve the issue I stackoverflowed below two lines and added to Manifest, but to no avail: android:hardwareAccelerated="true" android:usesCleartextTraffic="true"试图解决我在两行以下计算溢出并添加到清单中的问题,但无济于事: android:hardwareAccelerated="true" android:usesCleartextTraffic="true"
** 3. My java code is below:** ** 3. 我的 java 代码如下:**
(each of the settings I tried to comment out and then one by one uncomment, but still no result). (每一个设置我都试着注释掉然后一一取消注释,还是没有结果)。
public class MainActivity extends AppCompatActivity {公共 class MainActivity 扩展 AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView webView = findViewById(R.id.webView);
WebSettings settings = webView.getSettings();
settings.setDomStorageEnabled(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setDomStorageEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
webView.loadUrl("http://www.google.com");
}
} }
Could someone please check this is tell me what I've done wrong here?有人可以检查这是告诉我我在这里做错了什么吗? Thanks!谢谢!
Stupid thing, should not have done this late into the night.愚蠢的事情,不应该在深夜这样做。
The problem was only with layout, rest of the page was out of screen.问题仅在于布局,页面的 rest 超出了屏幕。 Needed only to match the WebView to constraints.只需要将 WebView 与约束相匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.