简体   繁体   English

Android Studio 中的 WebView 无法正确显示网站(即 www.google.com 没有徽标、搜索栏和屏幕上方的所有内容)

[英]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.问题

  • First screen shows normally google's asking user to accept their legal stuff (1st image).第一个屏幕通常显示谷歌要求用户接受他们的合法内容(第一张图片)。
  • After accepting it moves to google's main page.接受后,它会转到谷歌的主页。 But only lower part (Country, settings, adds, about etc.) is shown (2nd image).但只显示了较低的部分(国家、设置、添加、关于等)(第二张图片)。 There is no Google logo, no search bar and buttons and no stuff from the upper display (like GMAIL, GRAPHICS, ACCOUNT and so on).没有 Google 徽标,没有搜索栏和按钮,也没有来自上方显示屏的内容(如 GMAIL、GRAPHICS、ACCOUNT 等)。 1ST SCREEN OF GOOGLE.COM INCORRECTLY SHOWN GOOGLE PAGE GOOGLE.COM 的第一个屏幕显示不正确的GOOGLE 页面

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.

相关问题 Android,UnknownHostException:www.google.com,在设备上而不是模拟器上 - Android, UnknownHostException: www.google.com, on device,not emulator 如何在不使用Android Webview中的搜索栏的情况下显示Google搜索结果? - How to display Google search results without the search bar in Android webview? 我正在尝试在我的办公室中使用JAVA ping www.google.com,但不能ping相同 - I am trying to ping www.google.com using JAVA in my office but it is not pinging the same 的java.net.UnknownHostException:www.google.com - java.net.UnknownHostException:www.google.com 收到错误未知主机:www.google.com - getting error Unknow Host : www.google.com 命令find -number A www.google.com的正则表达式是什么? - What is the regular expression of the command find -number A www.google.com? 如何在较旧的 Android 设备(即 Gingerbread 和 Froyo)上显示首选项屏幕? - How can I show a preferences screen on older Android devices i.e. Gingerbread and Froyo? 如何在 Android Studio 的所有页面上保存功能(即 SFX 或音乐等设置)? - How to save a feature (i.e. setting like SFX or Music) across all pages in Android Studio? 迁移到旧版Android Studio(即3.1.2)上的androidx? - Migrate to androidx on older version of android studio i.e. 3.1.2? Android以编程方式包含布局(即没有XML) - Android programmatically include layout (i.e. without XML)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM