@@ -46,6 +46,8 @@ import androidx.annotation.StringRes
46
46
import androidx.appcompat.app.AppCompatActivity
47
47
import androidx.appcompat.widget.Toolbar
48
48
import androidx.core.content.FileProvider
49
+ import androidx.core.view.ViewCompat
50
+ import androidx.core.view.WindowInsetsCompat
49
51
import com.google.android.material.snackbar.Snackbar
50
52
import org.isoron.platform.gui.toInt
51
53
import org.isoron.uhabits.HabitsApplication
@@ -180,10 +182,10 @@ fun View.setupToolbar(
180
182
} else {
181
183
theme.color(color).toInt()
182
184
}
183
- val darkerColor = ColorUtils .mixColors(toolbarColor, Color .BLACK , 0.75f )
184
185
toolbar.background = ColorDrawable (toolbarColor)
186
+ toolbar.applyToolbarInsets()
185
187
val activity = context as AppCompatActivity
186
- activity.window.statusBarColor = darkerColor
188
+ activity.window.statusBarColor = toolbarColor
187
189
activity.setSupportActionBar(toolbar)
188
190
activity.supportActionBar?.setDisplayHomeAsUpEnabled(displayHomeAsUpEnabled)
189
191
}
@@ -245,3 +247,19 @@ fun View.getCenter(): PointF {
245
247
viewLocation[1 ] - = this .height / 2
246
248
return PointF (viewLocation[0 ].toFloat(), viewLocation[1 ].toFloat())
247
249
}
250
+
251
+ fun View.applyRootViewInsets () {
252
+ ViewCompat .setOnApplyWindowInsetsListener(this ) { view, insets ->
253
+ val systemBarsInsets = insets.getInsets(WindowInsetsCompat .Type .systemBars())
254
+ view.setPadding(systemBarsInsets.left, 0 , systemBarsInsets.right, systemBarsInsets.bottom)
255
+ insets
256
+ }
257
+ }
258
+
259
+ fun View.applyToolbarInsets () {
260
+ ViewCompat .setOnApplyWindowInsetsListener(this ) { view, insets ->
261
+ val systemBarsInsets = insets.getInsets(WindowInsetsCompat .Type .systemBars())
262
+ view.setPadding(0 , systemBarsInsets.top, 0 , 0 )
263
+ insets
264
+ }
265
+ }
0 commit comments