Skip to content

Commit

Permalink
better way to "transparent navigation bar"
Browse files Browse the repository at this point in the history
  • Loading branch information
sal0max committed Dec 16, 2021
1 parent 81c2567 commit 0496b7a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
19 changes: 0 additions & 19 deletions app/src/main/kotlin/de/salomax/currencies/view/BaseActivity.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package de.salomax.currencies.view

import android.content.Context
import android.graphics.Color
import android.os.Build
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.view.WindowInsetsControllerCompat
import com.google.android.material.color.MaterialColors
import de.salomax.currencies.R
import de.salomax.currencies.repository.Database

Expand All @@ -31,21 +26,7 @@ abstract class BaseActivity : AppCompatActivity() {
}
)

// "transparent" navigation bar
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
window.navigationBarColor = MaterialColors.getColor(this, R.attr.colorBackground, Color.BLACK)
WindowInsetsControllerCompat(window, window.decorView).isAppearanceLightNavigationBars = booleanFromAttribute(R.attr.isLightTheme)
WindowInsetsControllerCompat(window, window.decorView).isAppearanceLightStatusBars = booleanFromAttribute(R.attr.isLightTheme)
}

super.onCreate(savedInstanceState)
}

private fun Context.booleanFromAttribute(attribute: Int): Boolean {
val attributes = obtainStyledAttributes(intArrayOf(attribute))
val dimension = attributes.getBoolean(0, false)
attributes.recycle()
return dimension
}

}
16 changes: 16 additions & 0 deletions app/src/main/res/values-v27/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="AppTheme" parent="BaseAppTheme">
<!-- "transparent" navigation bar -->
<item name="android:navigationBarColor">?attr/colorBackground</item>
<item name="android:windowLightNavigationBar">?attr/isLightTheme</item>
</style>

<style name="AppTheme.Black" parent="BaseAppTheme.PureBlack">
<!-- "transparent" navigation bar -->
<item name="android:navigationBarColor">?attr/colorBackground</item>
<item name="android:windowLightNavigationBar">?attr/isLightTheme</item>
</style>

</resources>
8 changes: 6 additions & 2 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
<attr name="colorDisplayOverlay" format="reference|color" />
<attr name="colorBackground" format="reference|color" />

<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<!-- themes to be applied -->
<style name="AppTheme" parent="BaseAppTheme" />
<style name="AppTheme.PureBlack" parent="BaseAppTheme.PureBlack" />

<style name="BaseAppTheme" parent="Theme.MaterialComponents.DayNight">
<!-- colors -->
<item name="colorBackground">@color/colorBackground</item>
<item name="colorAccent">@color/colorAccent</item>
Expand Down Expand Up @@ -35,7 +39,7 @@
<item name="colorOnError">?android:attr/textColorPrimary</item>
</style>

<style name="AppTheme.PureBlack" parent="AppTheme">
<style name="BaseAppTheme.PureBlack" parent="AppTheme">
<!-- colors -->
<item name="colorBackground">@color/colorBackgroundPureBlack</item>
<item name="colorDisplayOverlay">@color/displayOverlayPureBlack</item>
Expand Down

0 comments on commit 0496b7a

Please sign in to comment.