V
V
Valentin Khoroshilov2019-06-19 22:50:28
Java
Valentin Khoroshilov, 2019-06-19 22:50:28

How to add YouTube fullscreen to WebView?

In one of the fragments of the program there is a WebView that opens YouTube, but for some reason there is no "expand to full screen" button, how to add it?

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class YouTubeFragment extends Fragment {


    public YouTubeFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        ((MainActivity)getActivity()).setActionBarTitle("YOUTUBE");

        View v = inflater.inflate(R.layout.fragment_you_tube, container, false);
        WebView webView = (WebView)v.findViewById(R.id.web3);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setWebViewClient(new WebViewClient());
        webView.loadUrl("https://www.youtube.com/");
        WebSettings webSettings = webView.getSettings();
        webSettings.setDomStorageEnabled(true);
        webSettings.setLoadWithOverviewMode(true); webSettings.setUseWideViewPort(true);
        webSettings.setSupportZoom(true); 
        
        return v;
    }

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2019-06-20
@402d

jascript youtube player api in android webview works terribly in my opinion.
better see how to work with it directly
https://developers.google.com/youtube/android/play...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question