Changing the color of Android's navigation bar

I’m currently trying to change the color of Android’s Navigation bar:

image

As well as the gesture navigation bar:

image

A couple of StackOverflow answers suggested adding the following to my MainActivity.java:

public class MainActivity extends BridgeActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        getWindow().setNavigationBarColor(Color.WHITE);
    }
}

But it doesn’t seem to do anything at all.

Has anyone been able to do this? I’m just looking to change the background and possibly change the icons to their light variation.

I did some more digging and testing and found this plugin.

I didn’t need to access the API as I wanted my color to just stay the same, so I simply copied the plugin’s source to my MainActivity.java.

// MainActivity.java

import com.getcapacitor.BridgeActivity;

import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

public class MainActivity extends BridgeActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            String color = "#FFFFFF";
            Boolean darkButtons = true;

            Window window = getWindow();
            int options = window.getDecorView().getSystemUiVisibility() | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;

            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && darkButtons) {
                options |= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
            } else {
                options &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
            }

            window.getDecorView().setSystemUiVisibility(options);
            window.setNavigationBarColor(Color.parseColor(color));
        }
    }
}