@@ -20,14 +20,23 @@ package com.bharathvishal.textfilegeneratorbenchmark
2020
2121
2222import android.content.Context
23+ import android.content.res.Configuration
24+ import android.os.Build
2325import android.os.Bundle
2426import android.os.Handler
2527import android.os.Looper
28+ import android.view.View
29+ import android.view.WindowInsets
2630import android.widget.LinearLayout
2731import android.widget.Toast
2832import androidx.activity.OnBackPressedCallback
33+ import androidx.activity.enableEdgeToEdge
2934import androidx.appcompat.app.AppCompatActivity
3035import androidx.appcompat.widget.Toolbar
36+ import androidx.core.view.ViewCompat
37+ import androidx.core.view.WindowInsetsCompat
38+ import androidx.core.view.updatePadding
39+ import com.google.android.material.color.DynamicColors
3140
3241class MainActivity : AppCompatActivity () {
3342
@@ -40,6 +49,14 @@ class MainActivity : AppCompatActivity() {
4049
4150
4251 override fun onCreate (savedInstanceState : Bundle ? ) {
52+ try {
53+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .VANILLA_ICE_CREAM ) {
54+ enableEdgeToEdge()
55+ }
56+ } catch (e: Exception ) {
57+ e.printStackTrace()
58+ }
59+
4360 super .onCreate(savedInstanceState)
4461 setContentView(R .layout.activity_main)
4562
@@ -52,6 +69,39 @@ class MainActivity : AppCompatActivity() {
5269
5370 activityContextMain = this @MainActivity
5471
72+ try {
73+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .VANILLA_ICE_CREAM ) {
74+ val viewTempAppBar = findViewById<View >(R .id.appbarmain)
75+ viewTempAppBar.setOnApplyWindowInsetsListener { view, insets ->
76+ val statusBarInsets = insets.getInsets(WindowInsets .Type .statusBars())
77+
78+ val nightModeFlags: Int = view.resources
79+ .configuration.uiMode and Configuration .UI_MODE_NIGHT_MASK
80+ val isDarkMode = nightModeFlags == Configuration .UI_MODE_NIGHT_YES
81+ val isDynamicTheme = DynamicColors .isDynamicColorAvailable()
82+ // Adjust padding to avoid overlap
83+ view.setPadding(0 , statusBarInsets.top, 0 , 0 )
84+ insets
85+ }
86+
87+
88+ val tempL: View = findViewById<View >(R .id.linearlayoutfragmentlayout)
89+ ViewCompat .setOnApplyWindowInsetsListener(tempL) { view, windowInsets ->
90+ val insets = windowInsets.getInsets(WindowInsetsCompat .Type .systemGestures())
91+ // Apply the insets as padding to the view. Here, set all the dimensions
92+ // as appropriate to your layout. You can also update the view's margin if
93+ // more appropriate.
94+ tempL.updatePadding(0 , 0 , 0 , insets.bottom)
95+
96+ // Return CONSUMED if you don't want the window insets to keep passing down
97+ // to descendant views.
98+ WindowInsetsCompat .CONSUMED
99+ }
100+ }
101+ } catch (e: Exception ) {
102+ e.printStackTrace()
103+ }
104+
55105 try {
56106 val mgr = supportFragmentManager
57107 val trans = mgr.beginTransaction()
0 commit comments