注意: 要设置fitsSystemWindows为true
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:fitsSystemWindows">true</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
设置字体颜色为黑色
setImmersiveStatusBar(Activity activity,boolean fontIconDark)
设置状态栏透明
setTranslucentStatus(Activity activity)
设置状态栏的颜色
setStatusBarColor(Activity activity, int colorId)
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StatusBarUtil.setImmersiveStatusBar(this,true);
}
}