【问题标题】:Android fullscreen while still showing the status barAndroid 全屏同时仍显示状态栏
【发布时间】:2019-08-14 08:37:12
【问题描述】:

我希望能够控制状态栏的背景并在其中显示颜色渐变,以便无缝过渡到状态栏下方的区域。

理想情况下,我将能够控制全屏以及状态栏所在的区域,并且状态栏将覆盖在我绘制的布局上。

这在 Android 中可能吗?如果是这样,我该如何设置styles.xml?

【问题讨论】:

标签: android android-theme


【解决方案1】:

试试这个

@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>

【讨论】:

    猜你喜欢
    • 2016-05-20
    • 1970-01-01
    • 1970-01-01
    • 2013-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-30
    • 2017-09-16
    相关资源
    最近更新 更多