Enable Fullscreen for Youtube videos in WebView

To enable fullscreen mode for YouTube videos in your sketchware project, follow the steps given below.

1. Create a new project in Sketchware.

2. In VIEW area add a WebView webview1.

3. Create a more block extra.

4. In the more block extra, use an add source directly blocks and put codes to define a new WebChromeClient class with name CustomWebClient.

public class CustomWebClient extends WebChromeClient {
private View mCustomView;
private WebChromeClient.CustomViewCallback mCustomViewCallback;
protected FrameLayout frame;

// Initially mOriginalOrientation is set to Landscape
private int mOriginalOrientation = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
private int mOriginalSystemUiVisibility;

// Constructor for CustomWebClient
public CustomWebClient() {}

public Bitmap getDefaultVideoPoster() {
if (MainActivity.this == null) {
return null; }
return BitmapFactory.decodeResource(MainActivity.this.getApplicationContext().getResources(), 2130837573); }

public void onShowCustomView(View paramView, WebChromeClient.CustomViewCallback viewCallback) {
if (this.mCustomView != null) {
return; }
this.mCustomView = paramView;
this.mOriginalSystemUiVisibility = MainActivity.this.getWindow().getDecorView().getSystemUiVisibility();
// When CustomView is shown screen orientation changes to mOriginalOrientation (Landscape).
// After that mOriginalOrientation is set to portrait.
this.mOriginalOrientation = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
this.mCustomViewCallback = viewCallback; ((FrameLayout)MainActivity.this.getWindow().getDecorView()).addView(this.mCustomView, new FrameLayout.LayoutParams(-1, -1)); MainActivity.this.getWindow().getDecorView().setSystemUiVisibility(3846);

public void onHideCustomView() {
this.mCustomView = null;
// When CustomView is hidden, screen orientation is set to mOriginalOrientation (portrait).
// After that mOriginalOrientation is set to landscape.
this.mOriginalOrientation = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; this.mCustomViewCallback.onCustomViewHidden();
this.mCustomViewCallback = null;


5. In onCreate event, use add source directly block and put codes to create a new CustomWebClient and set it as the WebChromeClient for the WebView.
webview1.setWebChromeClient(new CustomWebClient());

After that use webview loadUrl block to load youtube.

6. Now add a new event, 'On back button press', in LOGIC area of your app. In this event use if..else.. block. Add Webview goBack block as shown in image below. It should read, if WebView canGoBack then WebView goBack else Finish Activity.

7. Save and Run the project. You can now watch YouTube videos in fullscreen mode in your app.


  1. Sir I have created the quiz app using Json data. but after putting my own Json data the app crashes
    And make video how to automatically change the question in Json quiz app after certain delay of time and also show the timer

    1. Paste this code (oncreate) to not crashes app


    2. Thanks me later!

      I am "mark app studio philippines"

  2. Hey bro can you create how to aeccac all widgets like button or image view in view pager ? Please...

  3. Hello I can add Videos Ads in app Using Sketchware , I want to show other user how, I will Contact U

  4. hello i need ur help please i want to creat a chat room app how i can do it? i mean i need to do if user press on image (+) will see pop ask about room name ? if user type name of room,then creat a room

  5. Hi, I was wondering if it is possible to modify the video player of a webview instead of using the default device player

  6. Help me!
    I think it works only on main screen!
    I'm trying to add it on second screen but it is giving errors!
    Kindly tell me that what should i do for running youtube in full screen on second screen!
    Thank you!

    1. Hello, I'm having this exact problem right now, did you get it right?

    2. Copy the same come code and edit the webview1 into whichever webview you want

    3. Just change the main activity name into current page where webview exists

  7. can i active full screen option in any video

  8. This comment has been removed by the author.

  9. Sir plzz help

    How to get video view center of screen and how to change background color

    Plz plz help me

    1. WebView webview1; webview1=(WebView)findViewById(R.id.webview1); webview1.setBackgroundColor(0x00000000);

  10. Its working but it is not displaying the ads by google in the website.. Is there any solution for that??

  11. Thanks you so much bhai (Love you a lot) Thank you so much

  12. Bro I want to use YouTubePlayerView in Sketchware Pro. I wanna enable full screen button click. I can view the button but I can't go to full screen while clicking on it.. It seems to a dummy button now.

  13. Why click resize or press back is porce. Close app


Post a Comment

Popular posts from this blog

Simple car racing android game in Sketchware

A Flash Light App in Sketchware

Create a PDF reader android App in Sketchware

How to enable upload from webview in Sketchware?

How to enable download in webview in Sketchware apps?