Android6.0状态栏图标反色操作
代码方式:
public void setDarkStatusIcon(boolean bDark) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
View decorView =getWindow().getDecorView();
if(decorView != null){
int vis = decorView.getSystemUiVisibility();
if(bDark){
vis |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
} else{
vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
}
decorView.setSystemUiVisibility(vis);
}
getWindow().setStatusBarColor(Color.TRANSPARENT);
}
}
在Activity里面的onCreate函数里面调用setDarkStatusIcon(bDark)
Xml方式:
1、 首先在manifest.xml文件中声明为android:theme="@style/AppTheme"
2、 在styles.xml文件里面添加如下:
<style name="AppTheme" parent="android:Theme.Material.Light">
<!-- All customizations that are NOT specific to a particular API-levelcan go here. -->
<item name="android:colorPrimaryDark">#fff5f5f5</item>
<item name="android:colorPrimary">#fff5f5f5</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:windowTranslucentStatus">false</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>