0

我想将 youtube 的 web 版本放在我的应用程序中,您可以在其中执行所有操作(例如观看和搜索视频,..),而无需使用标准浏览器。我已经编写了这段代码,但每次弹出我想使用的浏览器(如谷歌浏览器,..)但我想让它显示在我的应用程序屏幕上,我已经设置了互联网的权限。

这里的代码:

youtube.xml:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <WebView
        android:id="@+id/webView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

youtube.java:

package com.example.listentomusic;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class Youtube extends Activity {

    public  void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.youtube);
    WebView wv = (WebView)findViewById(R.id.webView1);
    wv.loadUrl("http://www.youtube.com");
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub

    }    
}
4

1 回答 1

0

您需要创建您的 CustomWebViewClient 并将其设置为您的 webView。

像这样 -

 private class CustomWebViewClient extends WebViewClient {

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

现在将此设置CustomeWebViewClient为您的webView-

    WV.setWebViewClient(new CustomWebViewClient());

也是main(String[] args)没用的,删掉吧。

于 2013-09-13T21:48:54.573 回答