本文介绍了如何在WebView中全屏显示youtube视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_web_view_play_youtube);
WebView w = (WebView) findViewById(R.id.w);
w.setWebChromeClient(new WebChromeClient());
w.setWebViewClient(new WebViewClient());
w.getSettings().setJavaScriptEnabled(true);
w.loadUrl("https://www.youtube.com/watch?v=gY-HZg1Uwpc");
}
我得到以下屏幕截图
在此屏幕截图中,我看不到全屏按钮。
In this screenshot, I could not see "fullScreen" button.
推荐答案
在这种情况下,您必须首先在XML文件中添加 FrameLayout
。之后
In your case, you have to first add FrameLayout
in your XML file. After that
,您必须实现两种方法 onShowCustomView
和 onHideCustomView WebChromeClient
的c>如下所示:
you have to implement two methods onShowCustomView
and onHideCustomView
of WebChromeClient
as shown below:
FrameLayout customViewContainer = findViewById(R.id.customViewContainer);
webView.setWebChromeClient(new WebChromeClient() {
public void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback) {
super.onShowCustomView(view,callback);
webView.setVisibility(View.GONE);
customViewContainer.setVisibility(View.VISIBLE);
customViewContainer.addView(view);
}
public void onHideCustomView () {
super.onHideCustomView();
webView.setVisibility(View.VISIBLE);
customViewContainer.setVisibility(View.GONE);
}
});
这篇关于如何在WebView中全屏显示youtube视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!