android沉浸式标题栏
1、onCreate()添加以下代码放到setContentView()后面
//这个特性是安卓5.0以后才支持的所以需要对系统版本号做判断
if (Build.VERSION.SDK_INT>Build.VERSION_CODES.LOLLIPOP){
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|View.SYSTEM_UI_FLAG_LAYOUT_STABLE
);
getWindow().setStatusBarColor(Color.TRANSPARENT);
}
#2、res文件目录下创建values-v21文件,并创建styles.xml代码如下:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- 图片延伸到状态栏-->
<style name="MDTheme_IMAGE" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowTranslucentStatus">true</item>
<!--设置statusBarColor为透明-->
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
</resources>