How to set the status bar color in the whole device to green as the default phone app does?

80 views Asked by At

I'm making an app that can place and receive VoIP voice calls. As I want to mimic the default phone behavior, I want to do the same the system does when having a phone call: painting the status bar green while having a call, to highlight the user that he's on a call.

Just to clarify to avoid being marked as duplicated: this question is related to changing the status bar color not just in our Activity but in the whole device, as some phones when in a call.

Is it possible to achieve it?

1

There are 1 answers

2
adnandann On

Use something like this this (for versions > 23)

This is my old method. Some things are deprecated, find a solution and fix it

protected void setStatusBarColor(View view, int color, boolean isLight) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if(color == 0) color = ContextCompat.getColor(this, R.color.colorPrimaryDark);
        
        if(isLight) {
            int flags = view.getSystemUiVisibility();
            flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
            view.setSystemUiVisibility(flags);
        }
        //getWindow().setStatusBarColor(Color.WHITE);

        Window window = getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(color);
    }
}