SYSTEM_UI_FLAG_LIGHT_STATUS_BAR And FLAG_TRANSLUCENT_STATUS Is Deprecated
This code is deprecated in API 30. Any idea how to update this? private fun setSystemBarLight(act: Activity) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Solution 1:
These solutions only work on API >= 23.
UPDATE:
As suggested in the comment section, you can use WindowInsetsControllerCompat as follows.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Window window = getWindow();
View decorView = window.getDecorView();
WindowInsetsControllerCompat wic = new WindowInsetsControllerCompat(window, decorView);
wic.setAppearanceLightStatusBars(true); // true or false as desired.
// And then you can set any background color to the status bar.
window.setStatusBarColor(Color.WHITE);
}
OLD ANSWER:
In API level 30 setSystemUiVisibility() has been deprecated. Hence you should use WindowInsetsController. The below code will make the status bar light, that means the text in the statut bar will be black.
Window window = getWindow();
View decorView = window.getDecorView();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
WindowInsetsController wic = decorView.getWindowInsetsController();
wic.setSystemBarsAppearance(APPEARANCE_LIGHT_STATUS_BARS, APPEARANCE_LIGHT_STATUS_BARS);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
// set any light background color to the status bar. e.g. - white or light blue
window.setStatusBarColor(Color.WHITE);
to clear this, use
wic.setSystemBarsAppearance(0, APPEARANCE_LIGHT_STATUS_BARS);
Solution 2:
Yes now since it is deprecated, you can use:
window.setDecorFitsSystemWindows(false)
Then make sure you make the status bar transparent as well by adding below style to your app theme
<item name="android:navigationBarColor">@android:color/transparent</item>
Solution 3:
WindowCompat.setDecorFitsSystemWindows(window, false)
val wic = WindowCompat.getInsetsController(window, window.decorView)
wic?.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_BARS_BY_SWIPE
wic?.isAppearanceLightStatusBars = true
window.statusBarColor = Color.TRANSPARENT
Post a Comment for "SYSTEM_UI_FLAG_LIGHT_STATUS_BAR And FLAG_TRANSLUCENT_STATUS Is Deprecated"