Edge to Edge new api (#16)
This commit is contained in:
@@ -65,11 +65,11 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(platform("androidx.compose:compose-bom:2023.08.00"))
|
implementation(platform("androidx.compose:compose-bom:2023.10.01"))
|
||||||
implementation("androidx.activity:activity-compose:1.7.2")
|
implementation("androidx.activity:activity-compose:1.8.0")
|
||||||
implementation("androidx.compose.material3:material3")
|
implementation("androidx.compose.material3:material3")
|
||||||
implementation("androidx.compose.ui:ui")
|
implementation("androidx.compose.ui:ui")
|
||||||
implementation("androidx.compose.ui:ui-tooling-preview")
|
implementation("androidx.compose.ui:ui-tooling-preview")
|
||||||
implementation("androidx.core:core-ktx:1.10.1")
|
implementation("androidx.core:core-ktx:1.12.0")
|
||||||
debugImplementation("androidx.compose.ui:ui-tooling")
|
debugImplementation("androidx.compose.ui:ui-tooling")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import androidx.compose.material3.Surface
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.activity.enableEdgeToEdge
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import com.example.superheroes.model.HeroesRepository
|
import com.example.superheroes.model.HeroesRepository
|
||||||
@@ -36,6 +37,7 @@ import com.example.superheroes.ui.theme.SuperheroesTheme
|
|||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
enableEdgeToEdge()
|
||||||
setContent {
|
setContent {
|
||||||
SuperheroesTheme {
|
SuperheroesTheme {
|
||||||
// A surface container using the 'background' color from the theme
|
// A surface container using the 'background' color from the theme
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ package com.example.superheroes.ui.theme
|
|||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.view.View
|
|
||||||
import androidx.compose.foundation.isSystemInDarkTheme
|
import androidx.compose.foundation.isSystemInDarkTheme
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.darkColorScheme
|
import androidx.compose.material3.darkColorScheme
|
||||||
@@ -117,7 +116,9 @@ fun SuperheroesTheme(
|
|||||||
val view = LocalView.current
|
val view = LocalView.current
|
||||||
if (!view.isInEditMode) {
|
if (!view.isInEditMode) {
|
||||||
SideEffect {
|
SideEffect {
|
||||||
setUpEdgeToEdge(view, darkTheme)
|
val window = (view.context as Activity).window
|
||||||
|
window.statusBarColor = Color.Transparent.toArgb()
|
||||||
|
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = !darkTheme
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,23 +129,3 @@ fun SuperheroesTheme(
|
|||||||
content = content
|
content = content
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets up edge-to-edge for the window of this [view]. The system icon colors are set to either
|
|
||||||
* light or dark depending on whether the [darkTheme] is enabled or not.
|
|
||||||
*/
|
|
||||||
private fun setUpEdgeToEdge(view: View, darkTheme: Boolean) {
|
|
||||||
val window = (view.context as Activity).window
|
|
||||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
|
||||||
window.statusBarColor = Color.Transparent.toArgb()
|
|
||||||
val navigationBarColor = when {
|
|
||||||
Build.VERSION.SDK_INT >= 29 -> Color.Transparent.toArgb()
|
|
||||||
Build.VERSION.SDK_INT >= 26 -> Color(0xFF, 0xFF, 0xFF, 0x63).toArgb()
|
|
||||||
// Min sdk version for this app is 24, this block is for SDK versions 24 and 25
|
|
||||||
else -> Color(0x00, 0x00, 0x00, 0x50).toArgb()
|
|
||||||
}
|
|
||||||
window.navigationBarColor = navigationBarColor
|
|
||||||
val controller = WindowCompat.getInsetsController(window, view)
|
|
||||||
controller.isAppearanceLightStatusBars = !darkTheme
|
|
||||||
controller.isAppearanceLightNavigationBars = !darkTheme
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
plugins {
|
plugins {
|
||||||
id("com.android.application") version "8.1.1" apply false
|
id("com.android.application") version "8.1.3" apply false
|
||||||
id("com.android.library") version "8.1.1" apply false
|
id("com.android.library") version "8.1.3" apply false
|
||||||
id("org.jetbrains.kotlin.android") version "1.9.10" apply false
|
id("org.jetbrains.kotlin.android") version "1.9.10" apply false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user