@@ -7,9 +7,13 @@ import android.content.Intent
77import android.content.IntentFilter
88import android.os.Bundle
99import android.view.Gravity
10+ import android.view.ViewGroup
1011import android.widget.Button
12+ import android.widget.LinearLayout
1113import androidx.appcompat.app.ActionBar
1214import androidx.appcompat.app.AppCompatActivity
15+ import androidx.core.view.ViewCompat
16+ import androidx.core.view.WindowInsetsCompat
1317import androidx.localbroadcastmanager.content.LocalBroadcastManager
1418import org.json.JSONObject
1519import org.mozilla.geckoview.AllowOrDeny
@@ -69,6 +73,17 @@ class InAppBrowserActivity : AppCompatActivity() {
6973 override fun onCreate (savedInstanceState : Bundle ? ) {
7074 super .onCreate(savedInstanceState)
7175
76+ // Handle edge-to-edge display for Android 15+
77+ window.statusBarColor = android.graphics.Color .TRANSPARENT
78+ window.navigationBarColor = android.graphics.Color .TRANSPARENT
79+
80+ // Enable edge-to-edge
81+ ViewCompat .setOnApplyWindowInsetsListener(window.decorView) { view, windowInsets ->
82+ val insets = windowInsets.getInsets(WindowInsetsCompat .Type .systemBars())
83+ view.setPadding(0 , insets.top, 0 , insets.bottom)
84+ WindowInsetsCompat .CONSUMED
85+ }
86+
7287 val localBroadcastManager = LocalBroadcastManager .getInstance(this )
7388 localBroadcastManager.registerReceiver(
7489 closeReceiver,
@@ -95,13 +110,13 @@ class InAppBrowserActivity : AppCompatActivity() {
95110 setOnClickListener { onClose() }
96111 }
97112
98- val layoutParams =
113+ val actionBarLayoutParams =
99114 ActionBar .LayoutParams (
100115 ActionBar .LayoutParams .WRAP_CONTENT ,
101116 ActionBar .LayoutParams .WRAP_CONTENT ,
102117 Gravity .END or Gravity .CENTER_VERTICAL
103118 )
104- supportActionBar?.setCustomView(closeButton, layoutParams )
119+ supportActionBar?.setCustomView(closeButton, actionBarLayoutParams )
105120 supportActionBar?.setDisplayShowCustomEnabled(true )
106121
107122 OpacityCore .getRuntime()
@@ -199,7 +214,44 @@ class InAppBrowserActivity : AppCompatActivity() {
199214
200215 geckoView = GeckoView (this ).apply { setSession(geckoSession) }
201216
202- setContentView(geckoView)
217+ // Create a container layout to properly handle the action bar spacing
218+ val container = LinearLayout (this ).apply {
219+ orientation = LinearLayout .VERTICAL
220+ layoutParams = ViewGroup .LayoutParams (
221+ ViewGroup .LayoutParams .MATCH_PARENT ,
222+ ViewGroup .LayoutParams .MATCH_PARENT
223+ )
224+
225+ // Handle window insets for the container
226+ ViewCompat .setOnApplyWindowInsetsListener(this ) { view, windowInsets ->
227+ val insets = windowInsets.getInsets(WindowInsetsCompat .Type .systemBars())
228+ view.setPadding(0 , insets.top, 0 , insets.bottom)
229+ windowInsets
230+ }
231+ }
232+
233+ // Configure GeckoView layout params to account for action bar
234+ val geckoLayoutParams = LinearLayout .LayoutParams (
235+ LinearLayout .LayoutParams .MATCH_PARENT ,
236+ LinearLayout .LayoutParams .MATCH_PARENT
237+ ).apply {
238+ // Add top margin to account for action bar height
239+ val actionBarHeight = supportActionBar?.height ? : 0
240+ if (actionBarHeight == 0 ) {
241+ // Fallback to standard action bar height
242+ val typedArray =
243+ theme.obtainStyledAttributes(intArrayOf(android.R .attr.actionBarSize))
244+ topMargin = typedArray.getDimensionPixelSize(0 , 0 )
245+ typedArray.recycle()
246+ } else {
247+ topMargin = actionBarHeight
248+ }
249+ }
250+
251+ geckoView.layoutParams = geckoLayoutParams
252+ container.addView(geckoView)
253+
254+ setContentView(container)
203255 val url = intent.getStringExtra(" url" )!!
204256
205257 geckoSession.loadUri(url)
0 commit comments