3232import android .graphics .Color ;
3333
3434import android .widget .AbsoluteLayout ;
35+ import android .widget .FrameLayout ;
3536import android .view .ViewGroup .LayoutParams ;
37+ import android .view .WindowInsets ;
38+ import android .view .View ;
39+ import android .graphics .Insets ;
3640
3741import android .webkit .WebBackForwardList ;
3842import android .webkit .WebViewClient ;
@@ -177,7 +181,6 @@ public void onClick(DialogInterface dialog,int id) {
177181 String unencodedHtml = PythonActivity .mActivity .getString (R .string .loading_page_html );
178182 String encodedHtml = Base64 .encodeToString (unencodedHtml .getBytes (), Base64 .NO_PADDING );
179183 mWebView .loadData (encodedHtml , "text/html" , "base64" );
180- mWebView .setLayoutParams (new LayoutParams (LayoutParams .FILL_PARENT , LayoutParams .FILL_PARENT ));
181184 mWebView .setWebViewClient (new WebViewClient () {
182185 @ Override
183186 public boolean shouldOverrideUrlLoading (WebView view , String url ) {
@@ -200,8 +203,46 @@ public void onPageFinished(WebView view, String url) {
200203
201204 }
202205 });
203- mLayout = new AbsoluteLayout (PythonActivity .mActivity );
204- mLayout .addView (mWebView );
206+
207+ // Handle edge-to-edge insets only on Android 15+ (API 35+) where edge-to-edge is enforced
208+ if (android .os .Build .VERSION .SDK_INT >= 35 ) {
209+ // Use FrameLayout for Android 15+ to properly support margins for edge-to-edge
210+ mLayout = new FrameLayout (PythonActivity .mActivity );
211+
212+ // Set WebView with FrameLayout params that support margins
213+ FrameLayout .LayoutParams webViewParams = new FrameLayout .LayoutParams (
214+ FrameLayout .LayoutParams .MATCH_PARENT ,
215+ FrameLayout .LayoutParams .MATCH_PARENT
216+ );
217+ mWebView .setLayoutParams (webViewParams );
218+ mLayout .addView (mWebView );
219+
220+ mLayout .setOnApplyWindowInsetsListener (new View .OnApplyWindowInsetsListener () {
221+ @ Override
222+ public WindowInsets onApplyWindowInsets (View v , WindowInsets insets ) {
223+ // Get system bar insets using the Android 11+ API
224+ android .graphics .Insets systemBarsInsets = insets .getInsets (WindowInsets .Type .systemBars ());
225+
226+ // Apply margins to the WebView to avoid system bars
227+ FrameLayout .LayoutParams params = (FrameLayout .LayoutParams ) mWebView .getLayoutParams ();
228+ params .leftMargin = systemBarsInsets .left ;
229+ params .topMargin = systemBarsInsets .top ;
230+ params .rightMargin = systemBarsInsets .right ;
231+ params .bottomMargin = systemBarsInsets .bottom ;
232+ mWebView .setLayoutParams (params );
233+
234+ // Return the insets unchanged to allow other views to also handle them
235+ return insets ;
236+ }
237+ });
238+ // Enable edge-to-edge but handle insets properly
239+ mLayout .setFitsSystemWindows (false );
240+ } else {
241+ // For older Android versions, use the original AbsoluteLayout setup
242+ mLayout = new AbsoluteLayout (PythonActivity .mActivity );
243+ mWebView .setLayoutParams (new LayoutParams (LayoutParams .FILL_PARENT , LayoutParams .FILL_PARENT ));
244+ mLayout .addView (mWebView );
245+ }
205246
206247 setContentView (mLayout );
207248
0 commit comments