【问题标题】:Android - Make status bar icon color auto change by backgroundAndroid - 使状态栏图标颜色按背景自动更改
【发布时间】:2020-12-24 05:12:53
【问题描述】:

我通过这段代码修复了状态栏颜色为白色

<style name="BaseTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
    <item name="android:statusBarColor">@color/white</item>
    <item name="android:windowLightStatusBar" tools:targetApi="M">true</item>
</style>

所以,状态栏是白色的,图标是黑色的。

在我的项目中,我使用库 StfalconImageViewer 来显示图像。

private fun showImageViewer(sourceImageView: ImageView?, position: Int) {
    val imageLoader = ImageLoader<String> { imageView, imageUrl ->
        loadImage(imageView, imageUrl)
    }
    StfalconImageViewer.Builder(context, imageUrls, imageLoader)
            .withHiddenStatusBar(false)
            .withStartPosition(position)
            .withTransitionFrom(sourceImageView)
            .show()
}

当显示对话框时,我看到状态栏又回来了,图标也是黑色的(因为我用上面的代码固定了颜色)。

如何使状态栏图标颜色自动更改,如果状态栏为黑色,图标颜色自动更改为白色。或者,另一种询问方式:我想显示 StfalconImageViewer,状态栏图标颜色为白色。

请给我一些建议。

提前致谢。

【问题讨论】:

标签: android android-statusbar


【解决方案1】:

状态栏颜色以及状态栏图标颜色与您的背景颜色无关。所以你应该用手改变它。作为一种解决方案,我建议在状态栏下使用区域并使用一些库来获取大多数颜色,并根据它更改状态栏颜色。即使在这种情况下,有时它也可能无法正常工作。那么为什么不使用带有浅色图标的半透明深色背景呢。

附:你真的需要在案例中显示状态栏吗?也许最好为图像查看器进行全屏活动并仅在显示一些附加面板时显示状态栏。

【讨论】:

    猜你喜欢
    • 2015-09-26
    • 1970-01-01
    • 2019-11-20
    • 2016-10-16
    • 1970-01-01
    • 2012-02-21
    • 2019-11-05
    • 2018-06-22
    • 2015-10-09
    相关资源
    最近更新 更多