1

我有一个 webview 来显示一个网页。在该网页按钮单击事件中,我正在重定向到另一个页面。从那里另一个按钮单击事件即时重定向到第 3 页。我需要显示我的下一个活动,而不是重定向到第三页。

我正在使用以下代码,但我的第一页本身没有加载

            @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login_page);
    WebView webview = (WebView) findViewById(R.id.wvLogin);

    setContentView(webview);    
    webview.setWebViewClient(new WebViewClient()
    {
        // Override URL

        public boolean shouldOverrideUrlLoading(WebView view, String url)
        {
            if(url.equals("http://My 3rd page redirecting URL"))
            {                       
                Intent i = new Intent(getApplicationContext(), APImages.class);
                startActivity(i);                   
            }           
            return true;
        }

    });

    webview.loadUrl("http://Default URL to load first time");

}

请告诉我如何处理它?

4

3 回答 3

0

试试这个变种:

public boolean shouldOverrideUrlLoading(WebView view, String url)
{
    if(url.equals("http://My 3rd page redirecting URL"))
    {                       
        Intent i = new Intent(getApplicationContext(), APImages.class);
        startActivity(i);                   
    } else {
        webview.loadUrl(url);
    }
    return true;
}
于 2012-12-05T11:11:57.707 回答
0

试试 onLoadResource。这应该适用于 webview。有时 onOverride 函数不起作用,尤其是在您调用意图时。

于 2013-02-26T15:24:28.853 回答
0

当您不处理事件时,请尝试返回 false。这是来自WebClient参考。

True if the host application wants to leave the current WebView and handle the url itself, otherwise return false. 

你的代码应该是这样的。

webview.setWebViewClient(new WebViewClient()
{
    // Override URL

    public boolean shouldOverrideUrlLoading(WebView view, String url)
    {
        if(url.equals("http://My 3rd page redirecting URL"))
        {                       
            Intent i = new Intent(getApplicationContext(), APImages.class);
            startActivity(i);                   
            return true;
        }           
        return false;
    }

});
于 2012-12-05T10:58:01.583 回答