Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix translucent navbar for Android 10 #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

svank
Copy link
Contributor

@svank svank commented Feb 22, 2020

When the status bar is not hidden (i.e. StfalconImageViewer.Builder().withHiddenStatusBar(false)), past behavior was for the
navigation bar to be translucent. On Android 10 (SDK 29), it is opaque
black. See screenshot below, Android 9 on left and Android 10 on right

Screenshot from 2020-02-22 13-25-45

This patch restores and improves upon past behavior for Android 10 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). See screenshot below, Android 9 on left,
Android 10 center and right with three-button and gesture navigation.

Screenshot from 2020-02-22 15-25-23

I'm not 100% sure I've done this in the optimal way, but here's what I've found:

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 using 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.

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.
@svank svank force-pushed the fix-navbar-android-10 branch from ab9d815 to 27c248e Compare March 29, 2020 02:46
@benjictln
Copy link

Thanks for this PR ! It solved my issue, I copy pasted the code you added in styles.xml (in v29) and it worked for me.

@benjictln
Copy link

benjictln commented Nov 2, 2022

actually, it wasn't translucent for me, I actually added this code on my style.xml for anyone interested:

    <style name="ImageViewerDialog.DefaultBaseTheme" parent="android:Theme.Translucent.NoTitleBar">
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowTranslucentNavigation">true</item>
        <item name="android:navigationBarColor">@color/alwaysBlack</item>
    </style>
<!--  inspired by https://github.com/stfalcon-studio/StfalconImageViewer/pull/38, override the property of StfalconImageViewer lib -->
    <style name="ImageViewerDialog.Default" parent="ImageViewerDialog.DefaultBaseTheme">
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:windowTranslucentNavigation">true</item>
        <item name="android:navigationBarColor">@color/alwaysBlack</item>
    </style>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants