- 打开/res/themes/themes.xml
- 在
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.[应用名称]" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
下添加
<item name="android:statusBarColor" tools:targetApi="l">@color/white</item>
<item name="android:windowLightStatusBar">?attr/isLightTheme</item>
即可设置白天模式的状态栏的颜色为白色。
也可以使用系统预设的颜色:
<item name="android:statusBarColor" tools:targetApi="l">?attr/isLightTheme</item>
<item name="android:windowLightStatusBar">?attr/isLightTheme</item>
- 同理,修改/res/themes/themes.xml(night),可以设置暗黑模式下状态栏的颜色。