Android 中状态栏的默认色调是白色的(所以状态栏会变暗有点奇怪): I've found我可以在大于或等于 23 的 Android 版本中更改色调。 但后来我发现我设备上的几个应用程序(Android 5.1,API 22)使用黑色色调。他们是怎么做到的?
更新: 这就是我的意思: 其他一些App有浅色状态栏和黑色图标、时间标签等。
这是我的带有白色状态栏的应用示例:
我无法将 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/