blob: 55d3d7d385e7688621b152bcfb3e39c6240796c1 [file] [log] [blame] [view]
Peter E Connfc686482025-03-21 15:42:511# How WebView Full Screen Works
2
3[TOC]
4
5Note: In this doc, `WebView` in code font means the `WebView` class that's a
6subclass of `View`, whereas WebView in normal font means the WebView product in
7general.
8
9## How apps use full screen
10
11You can see an example of how to support WebView full screen in your application
12in [the WebView
13shell](https://source.chromium.org/chromium/chromium/src/+/main:android_webview/tools/system_webview_shell/apk/src/org/chromium/webview_shell/WebViewBrowserFragment.java;l=500;drc=cfb4fb0b1658a915db8c470751f511bb8360a9bc).
14The app overrides `WebChromeClient#onShowCustomView` to do something like:
15
16```java
17@Override
18public void onShowCustomView(
19 View view, WebChromeClient.CustomViewCallback callback) {
20 if (mFullscreenView != null) {
21 ((ViewGroup) mFullscreenView.getParent()).removeView(mFullscreenView);
22 }
23 mFullscreenView = view;
24 requireActivity()
25 .getWindow()
26 .addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
27 requireActivity()
28 .getWindow()
29 .addContentView(
30 mFullscreenView,
31 new FrameLayout.LayoutParams(
32 ViewGroup.LayoutParams.MATCH_PARENT,
33 ViewGroup.LayoutParams.MATCH_PARENT,
34 Gravity.CENTER));
35}
36```
37
38Essentially, when the web contents requests to go full screen, WebView creates a
39`View` (a
40[FullScreenView](https://source.chromium.org/chromium/chromium/src/+/main:android_webview/java/src/org/chromium/android_webview/FullScreenView.java))
41and hands it to the app to attach to the window. Usually the existing `WebView`
42remains attached to the window, but obscured by the full screen `View`.
43