Skip to content

Commit 8344a36

Browse files
Copilothossain-khan
andcommitted
Add edge-to-edge support to all activities and layouts
Co-authored-by: hossain-khan <99822+hossain-khan@users.noreply.github.com>
1 parent 102ac99 commit 8344a36

File tree

9 files changed

+57
-0
lines changed

9 files changed

+57
-0
lines changed

example/src/main/java/dev/hossain/ynaash/example/ui/MainActivity.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ package dev.hossain.ynaash.example.ui
33
import android.content.Intent
44
import android.os.Bundle
55
import android.widget.Button
6+
import androidx.activity.enableEdgeToEdge
67
import androidx.appcompat.app.AppCompatActivity
8+
import androidx.core.view.ViewCompat
9+
import androidx.core.view.WindowInsetsCompat
710
import dev.hossain.ynaash.example.R
811
import dev.hossain.ynaash.example.ui.demohighlightjs.HighlightJsDemoActivity
912
import dev.hossain.ynaash.example.ui.demoprismjs.PrismJsDemoActivity
@@ -14,9 +17,17 @@ import dev.hossain.ynaash.example.ui.demoprismjs.PrismJsComposeDemoActivity
1417
*/
1518
class MainActivity : AppCompatActivity() {
1619
override fun onCreate(savedInstanceState: Bundle?) {
20+
enableEdgeToEdge()
1721
super.onCreate(savedInstanceState)
1822
setContentView(R.layout.activity_main)
1923

24+
// Apply window insets to handle system bars
25+
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main_container)) { v, insets ->
26+
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
27+
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
28+
insets
29+
}
30+
2031
findViewById<Button>(R.id.highlightjs_demo_button).setOnClickListener {
2132
startActivity(Intent(this, HighlightJsDemoActivity::class.java))
2233
}

example/src/main/java/dev/hossain/ynaash/example/ui/demohighlightjs/HighlightJsDemoActivity.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package dev.hossain.ynaash.example.ui.demohighlightjs
22

33
import android.os.Bundle
4+
import androidx.activity.enableEdgeToEdge
45
import androidx.appcompat.app.AppCompatActivity
6+
import androidx.core.view.ViewCompat
7+
import androidx.core.view.WindowInsetsCompat
58
import dev.hossain.ynaash.example.R
69
import dev.hossain.ynaash.example.ui.common.SampleSourceCode
710
import dev.hossain.ynaash.highlightjs.SyntaxHighlighterFragment
@@ -16,11 +19,19 @@ import dev.hossain.ynaash.highlightjs.SyntaxHighlighterWebView
1619
*/
1720
class HighlightJsDemoActivity : AppCompatActivity() {
1821
override fun onCreate(savedInstanceState: Bundle?) {
22+
enableEdgeToEdge()
1923
super.onCreate(savedInstanceState)
2024
setContentView(R.layout.activity_demo_highlightjs)
2125

2226
supportActionBar?.title = "HighlightJS Demo"
2327

28+
// Apply window insets to handle system bars
29+
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.demo_container)) { v, insets ->
30+
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
31+
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
32+
insets
33+
}
34+
2435
loadSourceCodeFragment()
2536
loadSourceCodeCustomView()
2637
}

example/src/main/java/dev/hossain/ynaash/example/ui/demoprismjs/PrismJsComposeDemoActivity.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package dev.hossain.ynaash.example.ui.demoprismjs
22

33
import android.os.Bundle
44
import androidx.activity.compose.setContent
5+
import androidx.activity.enableEdgeToEdge
56
import androidx.appcompat.app.AppCompatActivity
67
import androidx.compose.foundation.layout.*
78
import androidx.compose.foundation.rememberScrollState
@@ -23,6 +24,7 @@ import dev.hossain.ynaash.example.ui.common.SampleSourceCode
2324
class PrismJsComposeDemoActivity : AppCompatActivity() {
2425

2526
override fun onCreate(savedInstanceState: Bundle?) {
27+
enableEdgeToEdge()
2628
super.onCreate(savedInstanceState)
2729

2830
supportActionBar?.title = "PrismJS Compose Demo"
@@ -45,6 +47,7 @@ fun PrismJsComposeDemoScreen() {
4547
Column(
4648
modifier = Modifier
4749
.fillMaxSize()
50+
.windowInsetsPadding(WindowInsets.systemBars)
4851
.padding(16.dp)
4952
.verticalScroll(rememberScrollState()),
5053
verticalArrangement = Arrangement.spacedBy(16.dp)

example/src/main/java/dev/hossain/ynaash/example/ui/demoprismjs/PrismJsDemoActivity.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package dev.hossain.ynaash.example.ui.demoprismjs
22

33
import android.os.Bundle
4+
import androidx.activity.enableEdgeToEdge
45
import androidx.appcompat.app.AppCompatActivity
6+
import androidx.core.view.ViewCompat
7+
import androidx.core.view.WindowInsetsCompat
58
import dev.hossain.ynaash.example.R
69
import dev.hossain.ynaash.example.ui.common.SampleSourceCode
710
import dev.hossain.ynaash.prismjs.SyntaxHighlighterFragment
@@ -16,11 +19,19 @@ import dev.hossain.ynaash.prismjs.SyntaxHighlighterWebView
1619
*/
1720
class PrismJsDemoActivity : AppCompatActivity() {
1821
override fun onCreate(savedInstanceState: Bundle?) {
22+
enableEdgeToEdge()
1923
super.onCreate(savedInstanceState)
2024
setContentView(R.layout.activity_demo_prismjs)
2125

2226
supportActionBar?.title = "PrismJS Demo"
2327

28+
// Apply window insets to handle system bars
29+
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.demo_container)) { v, insets ->
30+
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
31+
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
32+
insets
33+
}
34+
2435
loadSourceCodeFragment()
2536
loadSourceCodeCustomView()
2637
}

example/src/main/res/layout/activity_demo_highlightjs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
4+
android:id="@+id/demo_container"
45
android:layout_width="match_parent"
56
android:layout_height="match_parent"
67
android:orientation="vertical"

example/src/main/res/layout/activity_demo_prismjs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
4+
android:id="@+id/demo_container"
45
android:layout_width="match_parent"
56
android:layout_height="match_parent"
67
android:orientation="vertical"

example/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
4+
android:id="@+id/main_container"
45
android:layout_width="match_parent"
56
android:layout_height="match_parent"
67
android:layout_margin="24dp"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<resources>
2+
<!-- Base application theme for API 23+ -->
3+
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
4+
<!-- Customize your theme here. -->
5+
<item name="colorPrimary">@color/colorPrimary</item>
6+
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
7+
<item name="colorAccent">@color/colorAccent</item>
8+
9+
<!-- Enable edge-to-edge display -->
10+
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
11+
<item name="android:statusBarColor">@android:color/transparent</item>
12+
<item name="android:windowLightStatusBar">true</item>
13+
</style>
14+
15+
</resources>

example/src/main/res/values/styles.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
<item name="colorPrimary">@color/colorPrimary</item>
66
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
77
<item name="colorAccent">@color/colorAccent</item>
8+
9+
<!-- Enable edge-to-edge display -->
10+
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
811
</style>
912

1013
</resources>

0 commit comments

Comments
 (0)