X5webview Customize the Full screen interface

Source: Internet
Author: User

The integrated X5webview can choose whether full-screen mode is standard full screen or x5 full screen without setting the default to False.

First look at the basic settings for the standard fullscreen,

 if  (webview.getx5webviewextension ()! =   = new   Bundle (); Data.putboolean ( "Standardfullscreen", false ); //  Data.putboolean (" Supportlitewnd ", 
     
      false 
     ); //  data.putint (" Defaultvideoscreen ", 1); 
     
      //
       webview.getx5webviewextension (). In        Vokemiscmethod ("Setvideoparams" , data); }

If you are using standard fullscreen then the display page is as follows:

You can see the typical buttons that can be toggled on and off, the buttons for the lock screen, the buttons for caching and sharing, and the title of the video name. This is something that you might not want to see in some scenarios, such as a cache button, such as a page that was opened with a template to share with a template address.

Therefore, a standard full-screen mode is required instead of X5 full-screen mode.

Use the standard full-screen mode code as follows:

 if  (webview.getx5webviewextension ()! =   = new   Bundle (); Data.putboolean ( "Standardfullscreen", true ); //  Data.putboolean (" Supportlitewnd ", 
     
      false 
     ); //  data.putint (" Defaultvideoscreen ", 1); 
     
      //
       webview.getx5webviewextension (). In        Vokemiscmethod ("Setvideoparams" , data); }

The full-screen interaction needs to be handled internally, adding code to the layout as follows:

<framelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
Android:id= "@+id/webviewlayout"
android:orientation= "Vertical" >
 
<!--video fullscreen--<framelayout android:id = "@+id/video_fullvie W " Android:layout_width =" Fill_parent " and Roid:layout_height = "Fill_parent" Android:background =" @color/black " Span style= "color: #000000;" > android:visibility = "Gone" > <textview Android:id= "@+id/tv_touch" Android:layout_width =" 150DP " Android:layout_height = "45DP" android:layout_gravity =" R ight " Android:layout_margintop =" 20DP " Android:background = "@color/transparent"/> </framelayout>

</FrameLayout>

First, add a webviewchromeclient that handles callbacks for the Onshowcustomview, Onhidecustomview two methods. Add the following code to the class

PrivateIx5webchromeclient.customviewcallback Xcustomviewcallback; PrivateFramelayout Video_fullview;//Video Load View when full screen    PrivateView Xcustomview; PrivateCom.tencent.smtt.sdk.WebChromeClient xwebchromeclient =Newcom.tencent.smtt.sdk.WebChromeClient () {@Override Public voidOnprogresschanged (Com.tencent.smtt.sdk.WebView WebView,intpercent) {            Super. Onprogresschanged (WebView, percent); if(Percent > 40) {webview.setvisibility (view.visible); }        }        //methods for intercepting full-screen calls@Override Public voidOnshowcustomview (view view, Ix5webchromeclient.customviewcallback callback) {Super. Onshowcustomview (view, callback);            Getactivity (). Setrequestedorientation (Activityinfo.screen_orientation_landscape); LOG.E ("My", "Onshowcustomview----Xcustomview:" +Xcustomview);            Webview.setvisibility (view.invisible); //If a view already exists, then immediately terminate and create a new            if(Xcustomview! =NULL) {Callback.oncustomviewhidden (); return; }view.setvisibility (view.visible); Video_fullview.addview (view);Xcustomview =view;            Xcustomview.setvisibility (view.visible); Xcustomviewcallback=callback;        Video_fullview.setvisibility (view.visible); } @Override Public voidOnhidecustomview () {Super. Onhidecustomview (); LOG.E ("My", "Onhidecustomview----Xcustomview:" +Xcustomview); if(Xcustomview = =NULL){                //not full-screen playback status                return;            } getactivity (). Setrequestedorientation (activityinfo.screen_orientation_portrait);            Xcustomview.setvisibility (View.gone);            Video_fullview.removeview (Xcustomview); Xcustomview=NULL;            Video_fullview.setvisibility (View.gone);            Xcustomviewcallback.oncustomviewhidden ();        Webview.setvisibility (view.visible);    }    }; /*** Determine if it is full screen * *@return     */     Public BooleanIncustomview () {return(Xcustomview! =NULL); }    /*** Press the back key to exit full screen when full screen method*/     Public voidHidecustomview () {Xwebchromeclient.onhidecustomview ();    Getactivity (). Setrequestedorientation (activityinfo.screen_orientation_portrait); }

To set the webchrome of X5webview, the code is as follows:

Webview.setwebchromeclient (xwebchromeclient);

To handle the return event, you need to add the following code:

@Override      Public boolean onKeyDown (int  keycode, KeyEvent event) {    if (Incustomview () & & keycode = = keyevent.keycode_back) {                hidecustomview ()                ; return  ;        }     return Super . OnKeyDown (KeyCode, event);    }

That's it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.