【问题标题】:android webview Relatedandroid webview相关
【发布时间】:2012-09-01 22:51:51
【问题描述】:

我有多个 html 文件保存在 assets 文件夹中。我的 html 文件之一是:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
    .outer{width:300px; height:460px; padding:10px;}
</style>
</head>

<body>
<div class="outer">
    <h4 style="text-align:right; margin-bottom:30px; width:300px;"><a href="#0">HOME</a></h4>
    <h1>World Map -01</h1>
    <img src="world_map.png" width="300" alt="" />
    <h4 style="text-align:right; margin-top:30px; width:300px;"><a href="#2">NEXT</a></h4>
</div>
</body>
</html>

还有 3 个 html 文件与此相同。 将加载第一页。在这里我想通过检查href来获取href并手动加载链接。

我的代码是:

public class WebvwActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        WebView web=(WebView) findViewById(R.id.web);
        web.getSettings().setJavaScriptEnabled(true);
        web.loadUrl("file:///android_asset/demo.html");
}
}

我想通过检查 href 值来获取 href 值并加载链接?

提前致谢

【问题讨论】:

    标签: android webview android-webview webviewclient


    【解决方案1】:

    您可以为此使用 webview 的 WebViewClient。有一个函数shouldOverrideUrlLoading 可以用来检测href 的值并可以采取相应的行动。

    【讨论】:

      【解决方案2】:

      尝试使用以下方法之一以正常方式运行它:

      <li><a href="testing2.html" data-transition="none" rel="external">testing2</a></li>
      

      并将您的 testing2.html 文件放在 www 文件夹中

      【讨论】:

      • 我不想在 html 部分进行编辑。我需要编码来获取 href 值并加载链接。
      • 我想通过获取 href 值手动运行程序,并根据 href 值加载到下一页。
      猜你喜欢
      • 1970-01-01
      • 2016-05-10
      • 2011-01-17
      • 2017-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多