Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Update Android light/dark mode system bar theme (#520)

Leendert de Borstaf06bbfd1230
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/MainActivity.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/MainActivity.kt
index 450f161f9..dbea3d245 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/MainActivity.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/MainActivity.kt
@@ -1,5 +1,10 @@
package net.aliasvault.app
+import android.content.res.Configuration
+import android.os.Build
import android.os.Bundle
+import android.util.Log
+import android.view.WindowInsetsController
+import androidx.core.content.ContextCompat
import com.facebook.react.ReactActivity
import com.facebook.react.ReactActivityDelegate
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
@@ -11,6 +16,10 @@ import expo.modules.splashscreen.SplashScreenManager
* The main activity of the app.
*/
class MainActivity : ReactActivity() {
+ companion object {
+ private const val TAG = "MainActivity"
+ }
+
/**
* Called when the activity is created.
*/
@@ -24,6 +33,77 @@ class MainActivity : ReactActivity() {
// @generated end expo-splashscreen
super.onCreate(null)
+
+ // Configure system bars based on dark mode
+ configureSystemBars()
+ }
+
+ override fun onResume() {
+ super.onResume()
+ // Reapply system bar configuration when app resumes
+ // This ensures our settings persist even if other code tries to override them
+ configureSystemBars()
+ }
+
+ override fun onConfigurationChanged(newConfig: Configuration) {
+ super.onConfigurationChanged(newConfig)
+ // Reapply system bar configuration when theme changes
+ configureSystemBars()
+ }
+
+ /**
+ * Configure system bars (status bar and navigation bar) colors and appearance
+ * based on current theme (light/dark mode)
+ */
+ private fun configureSystemBars() {
+ val isDarkMode = (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
+ Log.d(TAG, "Configuring system bars - isDarkMode: $isDarkMode")
+
+ window.apply {
+ if (isDarkMode) {
+ // Dark mode: black background with light icons
+ val bgColor = ContextCompat.getColor(context, R.color.av_background)
+ Log.d(TAG, "Setting dark mode colors - bgColor: ${String.format("#%06X", 0xFFFFFF and bgColor)}")
+ statusBarColor = bgColor
+ navigationBarColor = bgColor
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
+ // Android 11+ (API 30+): Use WindowInsetsController
+ insetsController?.apply {
+ setSystemBarsAppearance(
+ 0, // Light icons/text
+ WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS or WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS,
+ )
+ }
+ } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ // Android 8-10 (API 26-29): Use deprecated flags
+ @Suppress("DEPRECATION")
+ decorView.systemUiVisibility = decorView.systemUiVisibility and
+ android.view.View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv() and
+ android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR.inv()
+ }
+ } else {
+ // Light mode: light gray background with dark icons
+ statusBarColor = ContextCompat.getColor(context, R.color.av_background)
+ navigationBarColor = ContextCompat.getColor(context, R.color.av_background)
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
+ // Android 11+ (API 30+): Use WindowInsetsController
+ insetsController?.apply {
+ setSystemBarsAppearance(
+ WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS or WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS,
+ WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS or WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS,
+ )
+ }
+ } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ // Android 8-10 (API 26-29): Use deprecated flags
+ @Suppress("DEPRECATION")
+ decorView.systemUiVisibility = decorView.systemUiVisibility or
+ android.view.View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR or
+ android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
+ }
+ }
+ }
}
/**
diff --git a/apps/mobile-app/android/app/src/main/res/values-night/styles.xml b/apps/mobile-app/android/app/src/main/res/values-night/styles.xml
index 6dcf2f04f..4b5e161dd 100644
--- a/apps/mobile-app/android/app/src/main/res/values-night/styles.xml
+++ b/apps/mobile-app/android/app/src/main/res/values-night/styles.xml
@@ -1,4 +1,16 @@
<resources xmlns:tools="http://schemas.android.com/tools">
+ <!-- Dark mode overrides for main app theme -->
+ <style name="AppTheme" parent="Theme.EdgeToEdge">
+ <item name="android:statusBarColor">@color/av_background</item>
+ <item name="android:navigationBarColor">@color/av_background</item>
+ <!-- Force opaque navigation bar (override EdgeToEdge transparency) -->
+ <item name="android:enforceNavigationBarContrast">false</item>
+ <item name="android:windowTranslucentNavigation">false</item>
+ <!-- Dark mode: use light icons/text on dark background -->
+ <item name="android:windowLightStatusBar">false</item>
+ <item name="android:windowLightNavigationBar">false</item>
+ </style>
+
<style name="PasskeyRegistrationTheme" parent="Theme.Material3.DayNight.NoActionBar">
<item name="colorPrimary">@color/av_primary</item>
<item name="colorOnPrimary">#FFFFFF</item>
diff --git a/apps/mobile-app/android/app/src/main/res/values/styles.xml b/apps/mobile-app/android/app/src/main/res/values/styles.xml
index ae251334b..646f14d48 100644
--- a/apps/mobile-app/android/app/src/main/res/values/styles.xml
+++ b/apps/mobile-app/android/app/src/main/res/values/styles.xml
@@ -3,9 +3,12 @@
<item name="android:textColor">@android:color/black</item>
<item name="android:editTextStyle">@style/ResetEditText</item>
<item name="colorPrimary">@color/colorPrimary</item>
- <item name="android:statusBarColor">#fff</item>
+ <item name="android:statusBarColor">@color/av_background</item>
<item name="android:navigationBarColor">#fff</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
+ <!-- Light mode: use dark icons/text on light background -->
+ <item name="android:windowLightStatusBar">true</item>
+ <item name="android:windowLightNavigationBar">true</item>
</style>
<style name="ResetEditText" parent="@android:style/Widget.EditText">
<item name="android:padding">0dp</item>