【问题标题】:webview loading网页视图加载
【发布时间】:2018-04-08 16:51:12
【问题描述】:

我正在尝试将 HTML 内容加载到 android Webview 中。我创建了一个下拉菜单,您可以在其中选择任何 HTML 内容,并且选择的 HTML 内容应加载到下面的 Web 视图中。但是数据加载不是很一致。 HTML 在桌面浏览器中正确呈现。 When a particular HTML content is selected Webview will display empty content and when tapped for 3-4 times data will load. When the HTML content is selected to load the previously selected content will also be present in the background.任何帮助将非常感激。使用下面提到的代码。

    WebView mWebViewContent = new WebView(getContext());
    mWebViewContent.getSettings().setJavaScriptEnabled(true);

    mWebViewContent.setWebChromeClient(new WebChromeClient());
    ViewGroup.LayoutParams params = mRelativeWebViewContent.getLayoutParams();
    mWebViewContent.clearHistory();
    mWebViewContent.clearFormData();
    mWebViewContent.clearCache(true);
    mWebViewContent.loadDataWithBaseURL(null, replaceHTML, "text/html", "UTF-8", null);
   // mWebViewContent.loadData(replaceHTML,"text/html","UTF-8");
    mRelativeWebViewContent.setLayoutParams(params);
    mRelativeWebViewContent.addView(mWebViewContent);

目前我正在以编程方式创建 Webview 并将其添加到相对布局中。添加使用 XML 时,我也遇到了同样的问题。

【问题讨论】:

    标签: android android-layout webview android-webview


    【解决方案1】:

    您正在创建一个新的 webview 并每次都在相对布局中添加。但是如果 relativelayout 已经包含 webview,您是否在添加之前将其删除

    【讨论】:

    • 哦,是的,感谢它现在的工作。但是当问题是加载时有两个 HTML 内容显示为空并且点击 3-4 次时仅显示数据。有什么解决办法吗?
    • 这不应该发生,因为 webview 是新创建的,所以加载 html 内容会显示或刷新 webview。问题可能是加载内容需要时间。你可以添加 webview 客户端并检查onPageFinished 在加载后调用。
    • 用 WebView 客户端试过,没有运气
    【解决方案2】:

    Add WebView only once in RelativeLayout in onCreate if is activity and when DropDpwn item is selected then just load that html content into webview.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-02-18
      • 2013-07-20
      • 1970-01-01
      • 1970-01-01
      • 2016-07-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多