I've tried to change the color of status bar content using isAppearanceLightStatusBars:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash_screen)
WindowCompat.setDecorFitsSystemWindows(window, false)
val controller = ViewCompat.getWindowInsetsController(window.decorView)
controller?.isAppearanceLightStatusBars = true
}
it doesn't change anything, but when i change it in theme xml file, it works normal:
<style name="Theme.NutShop" parent="Theme.MaterialComponents.NoActionBar">
<item name="android:windowLightStatusBar" tools:targetApi="23">true</item>
</style>
I need to know the reason of this problem, and solution, thanks.
CodePudding user response:
First you have add the below items to your base theme. Also note that your base theme name is added to your manifests application tag.
<item name="android:statusBarColor" tools:ignore="NewApi">@color/black</item>
<item name="android:windowLightStatusBar" tools:ignore="NewApi">false</item>
android:statusBarColor -> represents the color of your status bar
android:windowLightStatusBar -> represents the color of the icons and text on your status bar.
- True means that your status bar color is a light color so make the text and icons dark in color.
- False means that yyour status bar color is a dark color so make the text and icons light in color.
CodePudding user response:
I've found the problem, ViewCompat.getWindowInsetsController(window.decorView) is returning null, so i changed it with WindowCompat.getWindowInsetsController(window, window.decorView) then it worked now, but still don't know why the first one is returning null.