【问题标题】:Android load urls after loading custom html in webview在webview中加载自定义html后Android加载url
【发布时间】:2017-07-31 13:26:22
【问题描述】:

我正在开发 android 应用程序,我正在使用提交按钮和表单提交加载自定义 html 数据。稍后,当我从它要求外部浏览器的 html 内容内部重定向时,自定义 html 会在 webview 中成功加载。我怎样才能修复在同一个 webview 中工作?

这是我的代码:

 wb = (WebView)findViewById(R.id.webv);

        wb.getSettings().setLoadsImagesAutomatically(true);
        wb.getSettings().setJavaScriptEnabled(true);
        wb.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
String customHtml= "<html>...</html>"

wb.loadData(customHtml, "text/html", "UTF-8");

【问题讨论】:

    标签: android html webview


    【解决方案1】:

    添加这一行 wb.setWebViewClient(new WebViewClient());

    【讨论】:

    • 你能提供这个场景的任何工作示例吗?
    • @user6768912 有帮助吗?
    【解决方案2】:

    使用下面的代码;

    WebView view = new WebView(MainActivity.this);
    view.setVerticalScrollBarEnabled(false);
    
    ((LinearLayout)rootView.findViewById(R.id.text_about)).addView(view);
    
    view.loadData(getString(R.string.about), "text/html; charset=utf-8", "utf-8");
    

    在你的 string.xml 中

    <string name="about"><![CDATA[ <html> <head></head> <body style="text-align:justify;color:#059bba;background-color:#FF‌​F;"> here enter your text </body> </html> ]]> </string> 
    

    【讨论】:

    • 不再阅读我的问题.. 我的自定义 html 加载成功,之后当我按下提交按钮并在 url 上提交表单时,它要求外部浏览器
    猜你喜欢
    • 2014-04-08
    • 2017-06-27
    • 2022-07-13
    • 2013-04-18
    • 2016-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多