在Web视图中加载URL

时间:2011-06-02 07:08:39

标签: android

我有一个小问题,我想在网页视图中加载网址,但它没有显示在网页视图中,它显示在默认的Android浏览器中。我们如何抵制这种情况在webview中打开,如果我将使用任何其他网址,那么它只是在网页视图中显示。这个问题只有我特定的网址。解决方法是什么。

我的网址:http://www.bizrate.com/rd?t=http%3A%2F%2Fclickfrom.buy.com%2Fdefault.asp%3Fadid%3D17865%26sURL%3Dhttp%3A%2F%2Fwww.buy.com%2Fprod%2F4x-silicone-skin-soft-gel-case-for-htc-droid-incredible%2Fq%2Floc%2F111%2F219945395.html&mid=18893&cat_id=8515&atom=8517&prod_id=2513751439&oid=2388674793&pos=1&b_id=18&bid_type=4&bamt=45e4b920dcffc474&rf=af1&af_assettype_id=10&af_creative_id=6&af_id=50087&af_placement_id=1

我的代码:

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.storesite);

    //Bundle bundle = getIntent().getExtras();
    WebView web = (WebView)findViewById(R.id.web_store);
    //MyWebViewClient web1 = new MyWebViewClient();
    //web1.shouldOverrideUrlLoading(web, "http://www.bizrate.com/rd?t=http%3A%2F%2Fclickfrom.buy.com%2Fdefault.asp%3Fadid%3D17865%26sURL%3Dhttp%3A%2F%2Fwww.buy.com%2Fprod%2F4x-silicone-skin-soft-gel-case-for-htc-droid-incredible%2Fq%2Floc%2F111%2F219945395.html&mid=18893&cat_id=8515&atom=8517&prod_id=2513751439&oid=2388674793&pos=1&b_id=18&bid_type=4&bamt=45e4b920dcffc474&rf=af1&af_assettype_id=10&af_creative_id=6&af_id=50087&af_placement_id=1");
    web.getSettings().setJavaScriptEnabled(true);
    web.loadUrl("http://www.bizrate.com/rd?t=http%3A%2F%2Fclickfrom.buy.com%2Fdefault.asp%3Fadid%3D17865%26sURL%3Dhttp%3A%2F%2Fwww.buy.com%2Fprod%2F4x-silicone-skin-soft-gel-case-for-htc-droid-incredible%2Fq%2Floc%2F111%2F219945395.html&mid=18893&cat_id=8515&atom=8517&prod_id=2513751439&oid=2388674793&pos=1&b_id=18&bid_type=4&bamt=45e4b920dcffc474&rf=af1&af_assettype_id=10&af_creative_id=6&af_id=50087&af_placement_id=1");

}

2 个答案:

答案 0 :(得分:0)

像这样使用

 web.loadUrl("http://www.bizrate.com/rd?t=http%3A%2F%2Fclickfrom.buy.com%2Fdefault.asp%3Fadid%3D17865%26sURL%3Dhttp%3A%2F%2Fwww.buy.com%2Fprod%2F4x-silicone-skin-soft-gel-case-for-htc-droid-incredible%2Fq%2Floc%2F111%2F219945395.html&mid=18893&cat_id=8515&atom=8517&prod_id=2513751439&oid=2388674793&pos=1&b_id=18&bid_type=4&bamt=45e4b920dcffc474&rf=af1&af_assettype_id=10&af_creative_id=6&af_id=50087&af_placement_id=1");


    public class HelloWebViewClient extends WebViewClient {

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }

        }

答案 1 :(得分:0)

试试这个:

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // get the web view
    webView = (WebView) findViewById(R.id.webview);

    // prepare the web view
    registerForContextMenu(webView);
    webView.setWebViewClient(new ItemWebViewClient());
  }

  private class ItemWebViewClient extends WebViewClient {

    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
      // show progress bar

    }

    @Override
    public void onPageFinished(WebView view, String url) {
      // hide the progress bar

    }
  }