FR: Add method to change colour of iOS/Android status bar

EDIT: changed this into a feature request.

Hi there, perhaps someone can help me with this.

My app has dark and light modes which can either change automatically according to the system or can be manually set by the user (just as in messenger, telegram, etc.)

The atomatic setting works fine by regularly polling Desktop::getInstance().isDarkModeActive() and setting the appropiate colour mode of the app.

But when the user manually sets the mode to something different from the current system mode, the status bar has obviously the wrong colour.

Any ideas? There doesn’t seem to be a JUCE method to change the colour of the status bar.

Ok, in the end I sorted this out with a hack to the codebase. I’ll submit a feature request because it would be very easy to implement this properly in JUCE. My quick and dirty solution:

In juce_Desktop.h add a public variable:

int colourMode = 0; // 0 default, 1 light content, 2 dark content

And in change this:

- (UIStatusBarStyle) preferredStatusBarStyle
    return UIStatusBarStyleDefault;

to this:

- (UIStatusBarStyle) preferredStatusBarStyle
    if (Desktop::getInstance().colourMode == 2)
        return UIStatusBarStyleLightContent;

    else if (Desktop::getInstance().colourMode == 1)
    	if (@available(iOS 13.0, *)) 
            return UIStatusBarStyleDarkContent;

    return UIStatusBarStyleDefault;	

Then, to change the colour mode, from the mainComponent call:

Desktop::getInstance().colourMode = newColourMode;
Desktop::getInstance().setKioskModeComponent (getParentComponent(), false);
Desktop::getInstance().setKioskModeComponent (nullptr);

Setting and unsetting the kiosk mode causes iOS to update the change.

1 Like

I’ve added this functionality for iOS here:

On Android, I’m not sure whether a feature like this is necessary. At least on the emulator I used for testing, the status bar always had a black background, and the content was always legible.


Ah, that’s great, thanks a lot!