diff --git a/android/app/build.gradle b/android/app/build.gradle index a07b920..519d94c 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -47,6 +47,7 @@ dependencies { implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion" implementation "androidx.coordinatorlayout:coordinatorlayout:$androidxCoordinatorLayoutVersion" implementation "androidx.core:core-splashscreen:$coreSplashScreenVersion" + implementation "androidx.activity:activity-ktx:$androidxActivityVersion" implementation project(':capacitor-android') implementation project(':capacitor-cordova-android-plugins') implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" diff --git a/android/app/src/main/java/com/echo/app/MainActivity.java b/android/app/src/main/java/com/echo/app/MainActivity.java index 113bbf1..f97cab1 100644 --- a/android/app/src/main/java/com/echo/app/MainActivity.java +++ b/android/app/src/main/java/com/echo/app/MainActivity.java @@ -1,9 +1,9 @@ package com.echo.app; import android.os.Bundle; -import android.view.View; -import androidx.core.view.WindowCompat; -import androidx.core.view.WindowInsetsControllerCompat; +import android.graphics.Color; +import androidx.activity.EdgeToEdge; +import androidx.activity.SystemBarStyle; import com.getcapacitor.BridgeActivity; import com.echo.app.notification.NotificationBridgePlugin; @@ -16,13 +16,11 @@ public class MainActivity extends BridgeActivity { registerPlugin(NotificationBridgePlugin.class); super.onCreate(savedInstanceState); - // 让内容绘制到状态栏/导航栏后面,实现沉浸式效果 - WindowCompat.setDecorFitsSystemWindows(getWindow(), false); - - // 使用浅色背景 + 深色状态栏图标,避免黑色条块感 - View decorView = getWindow().getDecorView(); - WindowInsetsControllerCompat insetsController = - new WindowInsetsControllerCompat(getWindow(), decorView); - insetsController.setAppearanceLightStatusBars(true); + // 官方 Edge-to-Edge 实现:让内容延伸到状态栏和导航栏,小白条悬浮在内容之上 + EdgeToEdge.enable( + this, + SystemBarStyle.auto(Color.TRANSPARENT, Color.TRANSPARENT), + SystemBarStyle.auto(Color.TRANSPARENT, Color.TRANSPARENT) + ); } } diff --git a/android/variables.gradle b/android/variables.gradle index 232bd9d..cfe0381 100644 --- a/android/variables.gradle +++ b/android/variables.gradle @@ -1,8 +1,9 @@ ext { minSdkVersion = 22 - compileSdkVersion = 33 + // Edge-to-Edge 相关依赖(androidx.activity 等)要求至少 compileSdk 34 + compileSdkVersion = 34 targetSdkVersion = 33 - androidxActivityVersion = '1.7.0' + androidxActivityVersion = '1.9.0' androidxAppCompatVersion = '1.6.1' androidxCoordinatorLayoutVersion = '1.2.0' androidxCoreVersion = '1.10.0'