深色状态栏中的浅色文本在 Android 11 中不起作用

问题描述

我正在更改片段/活动之间的状态栏颜色和文本。对于黑色状态栏,我需要白色文本,反之亦然。由于 Android 11 上的 api 弃用,我正在使用它:

带有浅色文本的深色状态栏:

Window window = getwindow();
    if (mDefaultStatusBarColor == null) {
        mDefaultStatusBarColor = window.getStatusBarColor();
    }
    window.setStatusBarColor(ContextCompat.getColor(this,R.color.black));

    // Sets status text light
    View decorView = window.getDecorView();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
        WindowInsetsController wic = decorView.getwindowInsetsController();
        wic.setSystemBarsAppearance(0,APPEaraNCE_LIGHT_STATUS_BARS);
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        decorView.setsystemUIVisibility(decorView.getsystemUIVisibility() & ~View.SYstem_UI_FLAG_LIGHT_STATUS_BAR);
    }

更改为带有深色文本的浅色状态栏:

Window window = getwindow();
            // Giving the status bar its default color.
            if (mDefaultStatusBarColor != null) {
                window.setStatusBarColor(mDefaultStatusBarColor);
            }

            // Sets status text dark
            View decorView = window.getDecorView();

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
                WindowInsetsController wic = decorView.getwindowInsetsController();
                wic.setSystemBarsAppearance(APPEaraNCE_LIGHT_STATUS_BARS,APPEaraNCE_LIGHT_STATUS_BARS);
            } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                decorView.setsystemUIVisibility(View.SYstem_UI_FLAG_LIGHT_STATUS_BAR);
            }

但是第一种情况(带有浅色文本的深色状态栏)无法正常工作,因为文本仍然是深色的。

我有没有想添加一些东西?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...