简体   繁体   中英

Android - Make status bar icon color auto change by background

I fixed status bar color is white by this code

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

So, status bar is white, and icon is black.

图片

In my project, I use library StfalconImageViewer for show images.

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()
}

When dialog is showed, I seen status bar is back and icon is black too (because I fixed color with code above).

图片

How to make status bar icon color auto change, if status bar is black, icon color auto change to white. Or, another way of asking: I want to show StfalconImageViewer with status bar icon color is white.

Please give me some suggestion.

Thanks in advance.

Status bar color as well as status bar icons color is independent of your background color. So you should change it by hands. As a solution I would advice to take area under status bar and using some library get most colors and according to it change status bar colors. And even in the case sometimes it could work incorrectly. So why not use half transparent dark background with light icons.

PS Do you really need to show status bar in the case? Maybe it's better to make full screen activity for the image viewer and show status bar only when some additional panels are shown.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM