@@ -108,21 +108,48 @@ object ThemeModeState {
108108 }
109109 }
110110
111- private fun applyWindowFlags (activity : Activity ) {
112- if (! themeMode.isDarkMode) {
113- activity.window.run {
114- clearFlags(WindowManager .LayoutParams .FLAG_TRANSLUCENT_STATUS )
115- addFlags(WindowManager .LayoutParams .FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS )
116- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
117- var flags = View .SYSTEM_UI_FLAG_LAYOUT_STABLE or View .SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
118- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
119- flags = flags or View .SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
120- }
121- decorView.systemUiVisibility = flags
111+ private fun applyWindowFlags (activity : Activity ) {
112+ val window = activity.window
113+
114+ // 1. Kích hoạt chế độ tràn viền (Edge-to-Edge)
115+ androidx.core.view.WindowCompat .setDecorFitsSystemWindows(window, false )
116+ window.statusBarColor = android.graphics.Color .TRANSPARENT
117+ window.navigationBarColor = android.graphics.Color .TRANSPARENT
118+
119+ // 2. Tự động xử lý Padding cho Top và Bottom Bar
120+ val rootView = window.decorView.rootView
121+ androidx.core.view.ViewCompat .setOnApplyWindowInsetsListener(rootView) { _, insets ->
122+ val systemBars = insets.getInsets(androidx.core.view.WindowInsetsCompat .Type .systemBars())
123+
124+ // Tìm và đẩy padding cho Top Bar (Status Bar)
125+ activity.findViewById<View >(R .id.blur_top_container)?.setPadding(0 , systemBars.top, 0 , 0 )
126+
127+ // Tìm và đẩy padding cho Bottom Bar (Navigation Bar)
128+ activity.findViewById<View >(R .id.blur_bottom_container)?.setPadding(0 , 0 , 0 , systemBars.bottom)
129+
130+ insets
131+ }
132+
133+ // 3. Logic xử lý Icon sáng/tối hiện tại của bạn
134+ if (! themeMode.isDarkMode) {
135+ window.run {
136+ addFlags(WindowManager .LayoutParams .FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS )
137+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
138+ val controller = androidx.core.view.WindowInsetsControllerCompat (this , decorView)
139+ controller.isAppearanceLightStatusBars = true
140+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
141+ controller.isAppearanceLightNavigationBars = true
122142 }
123143 }
124144 }
145+ } else {
146+ // Đảm bảo icon màu trắng khi ở Dark Mode
147+ val controller = androidx.core.view.WindowInsetsControllerCompat (window, window.decorView)
148+ controller.isAppearanceLightStatusBars = false
149+ controller.isAppearanceLightNavigationBars = false
125150 }
151+ }
152+
126153
127154 fun getThemeMode (): ThemeMode = themeMode
128155}
0 commit comments