Good day, created an application for the site, the site has a video from YouTube video is played but does not go to full screen. Unfortunately, in WebView, such a function should be configured manually, please help? thank. Here are the solutions that I couldn’t find but: https://habrahabr.ru/company/mailru/blog/262167/ https://developer.android.com/reference/android/webkit/WebView.html

MAIN ACTIVITY.JAVA package com.kino_films.uzbekkino; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; public class MainActivity extends AppCompatActivity { private WebView mywebView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mywebView = (WebView)findViewById(R.id.webView); WebSettings webSettings = mywebView.getSettings(); webSettings.setJavaScriptEnabled(true); mywebView.loadUrl("http://kino-films.com"); mywebView.setWebViewClient(new WebViewClient()); } @Override public void onBackPressed() { if(mywebView.canGoBack()) { mywebView.goBack(); } else { super.onBackPressed(); } } } Manifest <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.kino_films.uzbekkino"> <uses-permission android:name="android.permission.INTERNET"></uses-permission> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> active main <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.kino_films.uzbekkino.MainActivity"> <WebView android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_centerHorizontal="true" android:id="@+id/webView" /> </RelativeLayout> 

I would be very grateful if you help. respectfully

  • When you click "full screen" on the web, the video is not displayed in full screen. I understood correctly? Show how it is shown. - Vladyslav Matviienko
  • @metalurgus is not, when you click "full screen" nothing happens. As in the code there is no processing of a web callback for a full-screen opening view. - xkor
  • @ user224437 you would describe in more detail why you can not use the solutions links to which resulted. In an article on Habré, everything seems to be quite clearly described. - xkor

1 answer 1

"full screen" video will have to be shown manually. This is done using the WebChromeClient :

 private class MyWebChromeClient extends WebChromeClient { //LayoutParams для режима FullScreen FrameLayout.LayoutParams layoutParameters = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT); @Override public void onShowCustomView(View view, CustomViewCallback callback) { // Если уже есть View для fullscreen, то убираем его if (mCustomView != null) { callback.onCustomViewHidden(); return; } //прячем обычный View (не fullscreen). Показано для примера, отредактироовать в зависимости от своей структуры mContentView = (RelativeLayout) findViewById(R.id.activity_main); mContentView.setVisibility(View.GONE); //создаем контейнер для fullscreen View mCustomViewContainer = new FrameLayout(MainActivity.this); mCustomViewContainer.setLayoutParams(layoutParameters); mCustomViewContainer.setBackgroundResource(android.R.color.black); view.setLayoutParams(layoutParameters); mCustomViewContainer.addView(view); mCustomView = view; mCustomViewCallback = callback; mCustomViewContainer.setVisibility(View.VISIBLE); //заменяем текущий ContentView setContentView(mCustomViewContainer); } @Override public void onHideCustomView() { if (mCustomView == null) { return; } else { // прячем Fullscreen View mCustomView.setVisibility(View.GONE); // убираем его из контейнера mCustomViewContainer.removeView(mCustomView); mCustomView = null; mCustomViewContainer.setVisibility(View.GONE); mCustomViewCallback.onCustomViewHidden(); // показываем обычный View mContentView.setVisibility(View.VISIBLE); setContentView(mContentView); } } } 

This is an example for use inside the Activity . You can make it easier by, for example, adding and removing a View over the current View inside the onShowCustomView and onHideCustomView