在 WebView 中显示 URL

2024-01-03

在我的 JsonParsing 中,我从这个 json 中获取了 url。我需要像在 web 视图中一样显示该 Url 链接。 我该怎么做?

Code在这儿:

     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 并执行以下操作

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;
    }
});

另一种方式是(这将在网络浏览器中打开)

Intent browserIntent = new Intent(Intent.ACTION_VIEW,uri.parse(url));
startActivity(browserIntent);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 WebView 中显示 URL 的相关文章

随机推荐