1

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?

Roc Boronat
  • 11,395
  • 5
  • 47
  • 59

1 Answers1

0

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);
    }
}
adnandann
  • 296
  • 3
  • 8
  • But as we will be working with `window`, when the user leaves the app, the status bar color will have the regular color, right? – Roc Boronat Feb 04 '21 at 10:33
  • This won't work this way because it's not possible to get a window object from the service but there is a way to create a transparent activity and keep the status bar in the color you want but I'm not sure that is what you want. I am very curious about this and when I have time in the next days I will try to do something .. if you find a solution I hope you will post here – adnandann Feb 04 '21 at 13:45