Android 全屏同时仍显示状态栏
Android fullscreen while still showing the status bar
我希望能够控制状态栏的背景并在其中显示颜色渐变,无缝过渡到状态栏下方的区域。
理想情况下,我将能够控制全屏以及状态栏所在的区域,并且状态栏将覆盖在我绘制的布局上。
在 Android 中可以吗?如果是这样,我该如何为它设置 styles.xml?
试试这个
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
fun changeStatusBarColor() {
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
window.statusBarColor = ContextCompat.getColor(this, android.R.color.transparent)
window.navigationBarColor = ContextCompat.getColor(this, android.R.color.transparent)
window.setBackgroundDrawableResource(R.drawable.drawable_gradient_theme)
}
drawable_gradient_theme
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="180"
android:endColor="#FF2080"
android:startColor="#FF8951" /><!--android:centerColor="#C12389"-->
</shape>
我希望能够控制状态栏的背景并在其中显示颜色渐变,无缝过渡到状态栏下方的区域。
理想情况下,我将能够控制全屏以及状态栏所在的区域,并且状态栏将覆盖在我绘制的布局上。
在 Android 中可以吗?如果是这样,我该如何为它设置 styles.xml?
试试这个
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
fun changeStatusBarColor() {
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
window.statusBarColor = ContextCompat.getColor(this, android.R.color.transparent)
window.navigationBarColor = ContextCompat.getColor(this, android.R.color.transparent)
window.setBackgroundDrawableResource(R.drawable.drawable_gradient_theme)
}
drawable_gradient_theme
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="180"
android:endColor="#FF2080"
android:startColor="#FF8951" /><!--android:centerColor="#C12389"-->
</shape>