项目中碰到修改状态栏颜色的需求,做个记录
代码
需要修改的Activity,onCreate中增加
//修改状态栏字体颜色为黑色
View decorView = getWindow().getDecorView();
int option = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
decorView.setSystemUiVisibility(option);
AndroidManifest.xml中
<activity android:name=".MainActivity"
android:theme="@style/AppTheme1">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
styles.xml中增加style,colorPrimaryDsark设置为白色背景,windowActionBar、windowNoTitle设置是为了取消actionbar
<style name="AppTheme1" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">#FFFFFF</item>
<item name="colorAccent">@color/colorAccent</item><!--
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>-->
</style>
手机型号HUAWEI Y62018,ATU-L22 亲测有效