Change the color of the status bar in minor versions to Android 5.0

3

I have a question about how to change the color of the status bar (StatusBar) of my application when the SDK version on the device is greater than or equal to 4.0 (API 14) . I currently have the following for when the SDK is greater than or equal to version 5.0 (API 21) and which works correctly for me:

public class LoginActivity extends AppCompatActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);        
    isColorNotifications();
  }

  ....
  ....

  private void isColorNotifications(){
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark));
    }
  }    
}

Maybe someone can give me some clue.

Thank you in advance.

    
asked by Brando T. 18.01.2016 в 23:58
source

1 answer

3

Good question, this was a design requirement in one of our Android applications, so we had the task of looking for how to change the color of the status bar.

Unfortunately, we find that for pre-Lollipop devices (-5.0) there is no way to programmatically change the color of the status bar , even if it could hardly be done with a future version of the support library.

  

Important to mention that this information was said by engineers from   Google.

    
answered by 30.01.2016 в 02:00