Window window = MainActivity.this.getWindow(); window.setStatusBarColor(MY_COLOR_IT_CAN_BE_ANY); if (Build.VERSION.SDK_INT < 30) { window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); } else { window.setDecorFitsSystemWindows(false); WindowInsetsController controller = getWindow().getInsetsController(); if(controller != null) { controller.setSystemBarsAppearance(WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS, WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS); } }
I am using this code for setting light status bar in android 11 and below android 11. Everything works fine, just a little problem, deprecation warning not going.
Advertisement
Answer
I just did one thing, since my if statement is fine, I just suppressed warning by using @SuppressWarnings(“deprecation”)
I just used this annotation for that particular method which contains this code.
There is another option present which is also perfectly fine: just add
//noinspection deprecation
above line of code which is deprecated. This will allow to check other warnings in that whole function. Which is good and I will prefer.
What is the advantage of //noinspection deprecation over @SuppressWarnings(“deprecation”)?
This prevents the problem with @SupressWarnings, which is it ignores all warnings in the method. So if you have something deprecated that you are not aware of, @SupressWarnings will hide it and you will not be warned. That is the advantage of the //noinspection
Courtest and check more details in this post answers: How to suppress specific Lint warning for deprecated Android function?