配置
- 在res/value/styles中配置状态栏的背景颜色
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Actionbar color -->
<item name="colorPrimary">@color/transparent</item>
<!--Status bar color-->
<item name="colorPrimaryDark">@color/transparent</item>
</style>
- 在manifest中定义使用AppTheme
<application
android:name=".MainApplication"
android:theme="@style/AppTheme">
- 在MainActivity的onCreate方法中使得页面全屏显示
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window window = getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
}