Skip to content

Commit 02684c5

Browse files
committed
fix: adjust toolbar padding to prevent content overlap with system bars
1 parent 31e70d8 commit 02684c5

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

app/src/main/java/org/kabiri/android/usbterminal/MainActivity.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,22 @@ class MainActivity : AppCompatActivity() {
3636
viewModel.startObservingUsbDevice()
3737
setContentView(R.layout.activity_main)
3838

39-
// avoid system navbar or soft keyboard overlapping the content.
4039
val rootView = findViewById<View>(R.id.root_view)
40+
val toolbar = findViewById<com.google.android.material.appbar.MaterialToolbar>(R.id.toolbar)
41+
setSupportActionBar(toolbar)
42+
4143
ViewCompat.setOnApplyWindowInsetsListener(rootView) { view, insets ->
4244
val systemBarsInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())
4345
val imeInsets = insets.getInsets(WindowInsetsCompat.Type.ime())
44-
view.setPadding(0, systemBarsInsets.top, 0, maxOf(systemBarsInsets.bottom, imeInsets.bottom))
46+
47+
// Toolbar consumes status bar space; content avoids bottom system bars
48+
toolbar.setPadding(
49+
toolbar.paddingLeft,
50+
systemBarsInsets.top,
51+
toolbar.paddingRight,
52+
toolbar.paddingBottom,
53+
)
54+
view.setPadding(0, 0, 0, maxOf(systemBarsInsets.bottom, imeInsets.bottom))
4555
insets
4656
}
4757

0 commit comments

Comments
 (0)