在 WebView 中显示 URL [英] Display URL in WebView

查看:42
本文介绍了在 WebView 中显示 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 JsonParsing 中,我从这个 json 中得到了 url.我需要在 webview 中显示该 Url 链接.我该怎么做?

In my JsonParsing and i got the url from this json. I need to display that Url link as in webview. How should i do that?

代码在这里:

     TextView tv = (TextView)findViewById(R.id.textView1);
     Bundle bundle = new Bundle();
     bundle  = getIntent().getExtras();

           String id = bundle .getString("id");
           String firstName = bundle.getString("firstName");
           String lastName = bundle.getString("lastName");
           String headline = bundle.getString("headline");
           String pictureUrl = bundle.getString("pictureUrl");
           String url = bundle.getString("url");


          Log.v("LV","id :"+id+"\n"+"firstname :"+firstName+"\n"+"lastname :"+lastName+"\n"+"headline :"+headline+"\n"+"pictureUrl :"+pictureUrl+"\n"+"siteStandardProfileRequest"+url);
          tv.setText("id :"+id+"\n"+"firstname :"+firstName+"\n"+"lastname :"+lastName+"\n"+"headline :"+headline+"\n"+"pictureUrl :"+pictureUrl+"\n"+"Profile URL :"+url);   

推荐答案

因为你要求在 webview 中打开 url 所以你必须在你的项目中使用一个 webview 并这样做

as you have ask for url open in webview so you have to take one webview in your project and do like this

webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(url);

// you need to setWebViewClient for forcefully open in your webview 
webview.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }
});

和其他方式是(这将在网络浏览器中打开)

and other way is (this will open in web browser)

Intent browserIntent = new Intent(Intent.ACTION_VIEW,uri.parse(url));
startActivity(browserIntent);

这篇关于在 WebView 中显示 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆