0

¿Hace falta alguna librería en especial para usar el siguiente código?

Más que nada, pregunto porque me sale toda la pantalla en blanco, no funciona.

public class Boxeo extends Fragment {

    WebView appWeb;

    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View v = inflater.inflate(R.layout.four_tab, container, false);

        getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

     //    String url = "<iframe src=\"https://www.youtube.com/playlist?list=PLxORtskANEIq4iBrXbMQvUtIQi_oDCk6c\" frameBorder=\"0\" \"allowFullScreen=\"allowFullScreen\"> </iframe>";
        appWeb = (WebView) v.findViewById(R.id.webView);

      //watch_popup para pantalla completa un solo video.

       // String url = "https://www.youtube.com/watch?v=JGPvwPJZddk&list=LLtfyXpymtaCHr6pwlkeGsjw";

       // appWeb = (WebView) v.findViewById(R.id.webView);
        //Habilitamos el javaScript y el zoom
     //   appWeb.getSettings().setJavaScriptEnabled(true);
        //appWeb.getSettings().setBuiltInZoomControls(true);
        //Cargamos el enlace definido
      //  appWeb.loadUrl(url);
        //Este método es para que el navegador se quede en nuestra aplicación
        //appWeb.setWebViewClient(new WebViewClient() {
       //     @Override
        //    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        //        return false;
         //   }
       // });

       // return v;


        String video = "<iframe class=\"youtube-player\" style=\"border: 0; width: 100%; height: 100%; padding:0px; margin:0px\" id=\"ytplayer\" type=\"text/html\" src=\"https://www.youtube.com/watch?v=JGPvwPJZddk&list=LLtfyXpymtaCHr6pwlkeGsjw\" frameborder=\"0\">\n" + "</iframe>\n";
        //appWeb.getSettings().setPluginState(WebSettings.PluginState.ON);
        appWeb.setWebChromeClient(new WebChromeClient());
        appWeb.getSettings().setJavaScriptEnabled(true);
        appWeb.setHorizontalScrollBarEnabled(false);
        appWeb.setVerticalScrollBarEnabled(false);
        appWeb.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        appWeb.getSettings().setBuiltInZoomControls(false);
        appWeb.getSettings().setAppCacheEnabled(true);
        appWeb.setInitialScale(0);
        appWeb.getSettings().setLoadWithOverviewMode(true);
        appWeb.getSettings().setUseWideViewPort(true);
        appWeb.loadUrl(video);


        return v;

    }
}

Estoy programando en Java. ¿Es la única solución?

1
  • Te refieres a hace que un webView este en full size en pantalla?, para eso solo con estylos, lo puedes hacer... el 2 feb. 2017 a las 18:03

1 respuesta 1

0

Puedes hacer que la pantalla este en full size, con esta funcion, o hacerlo con estilos

1.- Función para poner en modo full la pantalla ó volver a la normalidad, solo llámala de nuevo.

public void fullScreen() {

        // BEGIN_INCLUDE (get_current_ui_flags)
        // The UI options currently enabled are represented by a bitfield.
        // getSystemUiVisibility() gives us that bitfield.
        int uiOptions = getWindow().getDecorView().getSystemUiVisibility();
        int newUiOptions = uiOptions;
        // END_INCLUDE (get_current_ui_flags)
        // BEGIN_INCLUDE (toggle_ui_flags)
        boolean isImmersiveModeEnabled =
                ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions);
        if (isImmersiveModeEnabled) {
           System.out.println("Turning immersive mode mode off. ");
        } else {
           System.out.println("Turning immersive mode mode on.");
        }

        // Navigation bar hiding:  Backwards compatible to ICS.
        if (Build.VERSION.SDK_INT >= 14) {
            newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
        }

        // Status bar hiding: Backwards compatible to Jellybean
        if (Build.VERSION.SDK_INT >= 16) {
            newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN;
        }

        // Immersive mode: Backward compatible to KitKat.
        // Note that this flag doesn't do anything by itself, it only augments the behavior
        // of HIDE_NAVIGATION and FLAG_FULLSCREEN.  For the purposes of this sample
        // all three flags are being toggled together.
        // Note that there are two immersive mode UI flags, one of which is referred to as "sticky".
        // Sticky immersive mode differs in that it makes the navigation and status bars
        // semi-transparent, and the UI flag does not get cleared when the user interacts with
        // the screen.
        if (Build.VERSION.SDK_INT >= 18) {
            newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        }

        getWindow().getDecorView().setSystemUiVisibility(newUiOptions);
        //END_INCLUDE (set_ui_flags)
    }

2.- Con estilos, para hacer la pantalla full dependiendo la actividad

// archivo /res/values/styles.xml
<style name="MyWebviewBoxeo" parent="Theme.AppCompat.Light.Dialog">
    <item name="windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowIsFloating">false</item>
</style>

// archivo /manifests/androidmanifest.xml 
<activity
        android:name=".Boxeo"
        ...
        android:theme="@style/MyDialog"/>

3.- metodos para introducir custom html en webview.

String customHtml = "<html><body>Hello, WebView</body></html>";
webView.loadData(customHtml,"text/html", "UTF-8");

4.- si no te sale aun, puedes probar hacer esto

  • Crear custom php or javascript pagina, que le envies la url del video
  • retornar el iframe con la url
  • solo tendrias que hacer webView.loadUrl("http://blah.blah.com/sub.php?url=http://youtube.com/qweqwe");

Nota: por favor corrige tu pregunta para que otras personas puedan entender bien tu código, y tu pregunta, ya que aparece desacomodada...

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.