android - Android 版本 < 23 中的状态栏图标和文本色调

标签 android

Android 中状态栏的默认色调是白色的(所以状态栏会变暗有点奇怪): enter image description here I've found我可以在大于或等于 23 的 Android 版本中更改色调。 但后来我发现我设备上的几个应用程序(Android 5.1,API 22)使用黑色色调。他们是怎么做到的?

更新: 这就是我的意思: 其他一些App有浅色状态栏和黑色图标、时间标签等。

enter image description here

这是我的带有白色状态栏的应用示例:

enter image description here

我无法将 windowLightStatusBar 设置为 true 以使其在 API < 23 的设备中看起来像第一张图片中的应用。

最佳答案

对于 API 级别 < 23,将此添加到浅色背景上的深色图标的 Activity 中:

Window window = this.getWindow();
View view = window.getDecorView();
setLightStatusBar(view, this);

然后创建一个函数 setLightStatusBar,它将在浅色背景上显示深色图标:

public static void setLightStatusBar(View view, Activity activity) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

            int flags = view.getSystemUiVisibility();
            flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
            view.setSystemUiVisibility(flags);

            // You can change the background color of the status bar here
            activity.getWindow().setStatusBarColor(Color.WHITE);
        }
    }

对于 API 级别 23 及更高级别,只需将其添加到您的样式中即可

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="android:Theme.Material.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="android:windowLightStatusBar">true</item>
        <item name="android:statusBarColor">@android:color/white</item>
    </style>

</resources>

关于android - Android 版本 < 23 中的状态栏图标和文本色调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38553850/

相关文章:

php - 在 Android Studio 中用 Double 解析 JSONArray

android - 在 Toast .maketext() 方法中使用 getApplicationcontext() 和 this 有什么区别

android - AppBarLayout - 一旦进入 View ,布局有时是不可见的(即使它没有进入)

android - 检查android中的小屏幕支持

android - Swift 4 等效于 Kotlin "anonymous class"表示法

android - 确认返回提示退出应用

android - 如何通过android端编码使用firebase发送通知?

android - 如何将 google app-engine 应用程序与我的 android 连接?

android - 当我开始一个新线程时,我会强制关闭!

android - 目标设备不支持 'run-as' 命令