如何显示Youtube网站/视频中的网页视图? [英] How Do I Display Youtube site/video within Webview?

查看:742
本文介绍了如何显示Youtube网站/视频中的网页视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我小白到Android,我想浏览youtube.com和显示来自该网站的视频网页视图内。 Currenty,当我尝试这样做,设备的浏览器出现,让我使用设备浏览器浏览网站。如果web视图,是不是支持这种类型的功能,我如何将设备的默认浏览器在我的布局,我会网页视图,使该网站可以在应用程序中看到的。任何帮助是极大的AP preciated。

我的code迄今:

  huffingtonpost =(的WebView)findViewById(R.id.webView1);
    huffingtonpost.getSettings()setJavaScriptEnabled(真)。
    。huffingtonpost.getSettings()setUseWideViewPort(真);
    。huffingtonpost.getSettings()setLoadWithOverviewMode(真);
    尝试{
    huffingtonpost.loadUrl(http://www.youtube.com/KitcoNews);
    }赶上(例外五){
        e.printStackTrace();
    }


解决方案

处理页面导航这就解释了如何从打开默认/股的浏览器prevent Android系统。下面引用...


  

当用户点击从网页​​中的网页视图链接,默认行为是为Android推出处理的URL的应用程序。通常情况下,默认的Web浏览器中打开并加载目标网址。但是,您可以覆盖这个行为为您的WebView,所以你的链接的WebView中打开。


I am noob to android and i want to navigate youtube.com and show video from the site inside of a webview. Currenty, when i try to do this, the device's browser appears and makes me navigate the site using the device browser. If the webview, is not capable of this type of functionality, how do i place the device's default browser in my layout as i would a webview so that the site can be viewed within the application. Any help is greatly appreciated.

My code so far:

    huffingtonpost = (WebView)findViewById(R.id.webView1);
    huffingtonpost.getSettings().setJavaScriptEnabled(true);
    huffingtonpost.getSettings().setUseWideViewPort(true);
    huffingtonpost.getSettings().setLoadWithOverviewMode(true);
    try{
    huffingtonpost.loadUrl("http://www.youtube.com/KitcoNews");
    }catch (Exception e){
        e.printStackTrace();
    }

解决方案

Take a look at Handling Page Navigation which explains how to prevent Android from opening the default/stock browser. Quote below...

When the user clicks a link from a web page in your WebView, the default behavior is for Android to launch an application that handles URLs. Usually, the default web browser opens and loads the destination URL. However, you can override this behavior for your WebView, so links open within your WebView.

这篇关于如何显示Youtube网站/视频中的网页视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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