Skip to content

Commit 27c248e

Browse files
committed
Fix translucent navbar for Android 10
When the status bar is _not_ hidden, past behavior was for the navigation bar to be translucent. On Android 10 (SDK 29), it is opaque black. This patch restores and improves upon past behavior by ensuring a fully transparent nav bar when gesture controls are enabled (and using the system-provided translucent scrim when 3-button navigation is enabled). To achieve this we need to switch from using android:windowTranslucentNavigation to using android:navigationBarColor. On Android 10, it appears android:windowDrawsSystemBarBackgrounds must be set for android:navigationBarColor to have any affect. (I wonder if this is related to being an AlertDialog.) android:windowDrawsSystemBarBackgrounds is not supported in SDK < 21, whereas this library supports SDK >= 19, so I've created a separate styles.xml file for SDK >= 29. Setting systemUiVisibility flags appears to be necessary to get the transparent nav bar effect. It seems that setting android:windowTranslucentNavigation was providing the same effect as setting these flags, but now it needs to be done manually for SDK >= 29 as android:windowTranslucentNavigation is not set.
1 parent d11578f commit 27c248e

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

imageviewer/src/main/java/com/stfalcon/imageviewer/viewer/dialog/ImageViewerDialog.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package com.stfalcon.imageviewer.viewer.dialog
1818

1919
import android.content.Context
2020
import android.view.KeyEvent
21+
import android.view.View
22+
import android.view.WindowManager
2123
import android.widget.ImageView
2224
import androidx.appcompat.app.AlertDialog
2325
import com.stfalcon.imageviewer.R
@@ -39,6 +41,12 @@ internal class ImageViewerDialog<T>(
3941
else
4042
R.style.ImageViewerDialog_Default
4143

44+
private val dialogSystemUiVisibility: Int
45+
get() = if (builderData.shouldStatusBarHide)
46+
0
47+
else
48+
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
49+
4250
init {
4351
setupViewerView()
4452
dialog = AlertDialog
@@ -50,6 +58,7 @@ internal class ImageViewerDialog<T>(
5058
setOnShowListener { viewerView.open(builderData.transitionView, animateOpen) }
5159
setOnDismissListener { builderData.onDismissListener?.onDismiss() }
5260
}
61+
dialog.window?.decorView?.systemUiVisibility = dialogSystemUiVisibility
5362
}
5463

5564
fun show(animate: Boolean) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
4+
<style name="ImageViewerDialog.Default" parent="ImageViewerDialog.DefaultBaseTheme">
5+
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
6+
<item name="android:navigationBarColor">@android:color/transparent</item>
7+
</style>
8+
9+
</resources>

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55

66
<style name="ImageViewerDialog.NoStatusBar" parent="android:Theme.Translucent.NoTitleBar.Fullscreen"/>
77

8-
<style name="ImageViewerDialog.Default" parent="android:Theme.Translucent.NoTitleBar">
8+
<style name="ImageViewerDialog.DefaultBaseTheme" parent="android:Theme.Translucent.NoTitleBar">
99
<item name="android:windowTranslucentStatus">true</item>
10+
</style>
11+
12+
<style name="ImageViewerDialog.Default" parent="ImageViewerDialog.DefaultBaseTheme">
1013
<item name="android:windowTranslucentNavigation">true</item>
1114
</style>
1215

0 commit comments

Comments
 (0)